Develop a Perl Script Using CGI- Assignment

Added on - 25 Sep 2019

  • 4

    pages

  • 1356

    words

  • 113

    views

  • 0

    downloads

Showing pages 1 to 2 of 4 pages
Perl and CGImain body start Your task for this practical assignment consists of twoparts:1Develop a Perl script usingCGI.pmfor that performs a statisticalanalysis of program code and provides functionality stated in theRequirements sectionbelow.2Make the Perl script that you have created accessible and usable viathe URLhttp://cgi.csc.liv.ac.uk/cgi-bin/cgiwrap/<youruser name>/analysis.pltaking care that the access rights forthe fileanalysis.plare neither too restrictive nor too permissive.RequirementsYour Perl script should perform a statistical analysis of program codethat the user provides via a web interface either by supplying a URL thatindicates where the code can be retrieved or by entering the codedirectly into a text field.The script should display a web page that contains a form with two textfields and a `Submit' button. The first text field should allow a user toenter a single URL. You do not need to check whether the URL issyntactically well-formed.If a user enters a URL into the first text field and presses the `Submit'button, then your script should retrieve the code that the URL points to.You should cater for the possibility that the URL is not valid, i.e., thatthere is nothing to retrieve at that URL, and indicate an error to the userin such a case. The code may not only ASCII characters but also UTF-8characters and your script should handle those characters correctlywhen performing the analysis.The second text field allows the user to directly enter program code.Again, you should assume that the code may contain UTF-8 characters.If a user presses the `Submit' button, then your script should simply takethe code that has been entered and proceed.An example document that your script is expected to analyse is thefollowing/* This isamulti-line comment */if ($counter > 0) {print("$counter is zero") // comment to the end of theline} else {# single-line comment
print("$counter is not zero)}You do not need to check whether the code is syntactically correct (inany programming language).A user may enter both a URL into the first text field and code into yoursecond text field and then press the `Submit' button. In such a case yoursystem should indicate an error and allow the user to start again.Your script should determine the amount of comments in the code andthe amount of instructions and other constructs that are not commentsthere are in the code:Single-line comments either start with#or with//and run until the endof the line. Thenumber of non-empty lines of commentfor a single-linecomment is 1 if the comment contains at least one Unicode wordcharacter and 0 otherwise. Multi-line comments start with/*and endwith*/and span one or more lines between/*and*/. Thenumber ofnon-empty lines of commentfor a multi-line comment is the number oflines of that comment that contain at least one Unicode word character.Thelength of a comment, for both single-line and multi-line comments, isthe number of Unicode word characters in a comment. Thenumber ofwords in a comment, for both single-line and multi-line comments, issimply the number of words in a comment where we assume that awordis a non-empty sequence of Unicode word characters separated by non-word characters. Finally, thenumber of non-trivial commentsis thenumber of single-line and multi-line comments that is at least five wordslong (note: here a multi-line comment counts 1 no matter how many linesit has, if it contains at least five word). You can assume that commentscannot be nested.If you remove all comments from the code, including the characters thatstart and end comments, as well as any empty lines and any linescontaining only spaces and tabs, what remains are theinstructionsofthe code. We are interested in thenumber of elements of instructionandthenumber of lines of instruction. Anelement of instructionis either anidentifier, that is, a non-empty sequence of the characters a-z, A-Z, 0-9,and underscore_that does not start with a digit, or a non-emptysequence of the symbols+,*,-,%,!,=,&,|. Aline of instructionis aline in the instructions that contains at least one element of instruction.Your script should first output the code it has received as input, in a waythat preserves the layout and all elements of the code. Your scriptshould then determine and output as a tablethe number of lines of instruction,the number of elements of instruction,the number of non-empty lines of comment,
desklib-logo
You’re reading a preview
card-image

To View Complete Document

Become a Desklib Library Member.
Subscribe to our plans

Download This Document