Develop a Perl Script Using CGI- Assignment

Added on -2019-09-25

| 4 pages
| 1356 words

Trusted by 2+ million users,
1000+ happy students everyday

Showing pages 1 to 2 of 4 pages

Perl and CGImain body start Your task for this practical assignment consists of two parts:1Develop a Perl script using for that performs a statistical analysis of program code and provides functionality stated in the Requirements section below.2Make the Perl script that you have created accessible and usable via the URL<your user name>/ taking care that the access rights forthe file are neither too restrictive nor too permissive.RequirementsYour Perl script should perform a statistical analysis of program code that the user provides via a web interface either by supplying a URL that indicates where the code can be retrieved or by entering the code directly into a text field.The script should display a web page that contains a form with two text fields and a `Submit' button. The first text field should allow a user to enter a single URL. You do not need to check whether the URL is syntactically 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., that there is nothing to retrieve at that URL, and indicate an error to the user in such a case. The code may not only ASCII characters but also UTF-8 characters and your script should handle those characters correctly when 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 take the code that has been entered and proceed.An example document that your script is expected to analyse is the following/* This is a multi-line comment */if ($counter > 0) { print("$counter is zero") // comment to the end of the line} else { # single-line comment
print("$counter is not zero)}You do not need to check whether the code is syntactically correct (in any programming language).A user may enter both a URL into the first text field and code into your second 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 and the amount of instructions and other constructs that are not comments there are in the code:Single-line comments either start with # or with // and run until the end of the line. The number of non-empty lines of comment for a single-line comment is 1 if the comment contains at least one Unicode word character and 0 otherwise. Multi-line comments start with /* and end with */ and span one or more lines between /* and */. The number of non-empty lines of comment for a multi-line comment is the number of lines of that comment that contain at least one Unicode word character. The length of a comment, for both single-line and multi-line comments, isthe number of Unicode word characters in a comment. The number of words in a comment, for both single-line and multi-line comments, is simply the number of words in a comment where we assume that a wordis a non-empty sequence of Unicode word characters separated by non-word characters. Finally, the number of non-trivial comments is the number of single-line and multi-line comments that is at least five words long (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 comments cannot be nested.If you remove all comments from the code, including the characters that start and end comments, as well as any empty lines and any lines containing only spaces and tabs, what remains are the instructions of the code. We are interested in the number of elements of instruction andthe number of lines of instruction. An element of instruction is either an identifier, 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-empty sequence of the symbols +, *, -, %, !, =, &, |. A line of instruction is a line 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 way that preserves the layout and all elements of the code. Your script should 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,

Found this document preview useful?

You are reading a preview
Upload your documents to download
Become a Desklib member to get accesss

Students who viewed this