logo

Develop a Perl Script Using CGI- Assignment

4 Pages1356 Words50 Views
   

Added on  2019-09-25

Develop a Perl Script Using CGI- Assignment

   Added on 2019-09-25

ShareRelated Documents
Perl and CGImain body start Your task for this practical assignment consists of two parts:1Develop a Perl script using CGI.pm 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 http://cgi.csc.liv.ac.uk/cgi-bin/cgiwrap/<your user name>/analysis.pl taking care that the access rights forthe file analysis.pl 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
Develop a Perl Script Using CGI- Assignment_1
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,
Develop a Perl Script Using CGI- Assignment_2

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Perl and CGI Practical Assignment: Statistical Analysis of Program Code
|4
|1356
|440

Web-based System Using HTML, PHP & MySQl | Assignment
|5
|1729
|211

The Programming Paradigms : Assignment
|3
|1194
|607