COMP284 Perl and CGI.pm Practical

Verified

Added on  2019/09/25

|4
|1356
|50
Practical Assignment
AI Summary
This practical assignment requires students to develop a Perl script using CGI.pm to perform a statistical analysis of program code provided via a web interface. The script should accept code either through a URL or direct input, handle UTF-8 characters, and analyze comments and instructions. The analysis includes determining the number of lines of instruction, elements of instruction, non-empty lines of comment, non-trivial comments, and words in comments. The script should also calculate ratios between these metrics and display the results in a table. The assignment emphasizes proper commenting and referencing of external sources. The completed script must be accessible via a specified URL, and the assignment contributes 30% to the overall module grade.
tabler-icon-diamond-filled.svg

Contribute Materials

Your contribution can guide someone’s learning journey. Share your documents today.
Document Page
Perl and CGI
main body start Your task for this practical assignment consists of two
parts:
1 Develop a Perl script using CGI.pm for that performs a statistical
analysis of program code and provides functionality stated in the
Requirements section below.
2 Make 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 for
the file analysis.pl are neither too restrictive nor too permissive.
Requirements
Your 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
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
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 your
system 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, is
the 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 word
is 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 lines
it 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 and
the 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 table
the number of lines of instruction,
the number of elements of instruction,
the number of non-empty lines of comment,
Document Page
the number of non-trivial comments,
the number of words of comment,
the ratio of the number of non-empty lines of comment to the number
lines of instruction,
the ratio of the number of non-trivial comments to the number lines of
instruction,
the ratio of the number of words of comment to the number of
elements of instruction.
Ratios should be rounded to 1 digit after the decimal point.
For the code example above the output would be:
Code Analysis
Number of lines of instruction 4
Number of elements of instruction 1
2
Number of non-empty lines of comment 5
Number of non-trivial comments 2
Number of words of comment 1
6
Ratio of lines of comment to lines of instruction 1
.
2
Ratio of non-trivial comment to lines of instruction 0
.
5
Ratio of words of comment to elements of
instruction
1
.
3
Your code should be properly commented. This includes pointing out
which parts of your code have been developed with the help of on-line
sources or textbooks and references for these sources.
Submission
Submit your Perl script via the departmental submission system at
https://sam.csc.liv.ac.uk/COMP/Submissions.pl?module=comp284
(COMP284-11: Re-sit: Perl and CGI.pm). Do not forget to also complete
the second part of the assignment.
Deadline
The deadline for this practical assignment is
Tuesday, 16 August 2016, 17:00
Document Page
Earlier submission is possible, but any submission after the deadline
attracts the standard lateness penalties. Please remember that a strict
interpretation of `lateness' is applied by the Department, that is, a
submission on Tuesday, 16 August 2016, 17:01 is considered to be a
day late (analogously for submissions that are delayed further).
Assessment
This practical assignment will address the following learning outcomes of
the module:
rapidly develop simple applications, both computer and web-based,
using an appropriate scripting language;
document and comment applications written using a scripting
language.
This practical assignment will contribute 30% to the overall mark of
COMP284. Failure on this assignment may be compensated by higher
marks on other assignments for this module.
Marks will be awarded according to the following scheme:
The Perl script is accessible via the required URL, the access rights of
the script are not too permissive, and the script works without
producing script errors: 10%
Creating a web page, using CGI.pm, for user input, input checking and
URL retrieval: 25%
Performing the code analysis: 37%
Creating a web page, using CGI.pm, showing the program code and
the results of the analysis: 16%
Formatting, commenting, and quality of code: 12%
chevron_up_icon
1 out of 4
circle_padding
hide_on_mobile
zoom_out_icon
logo.png

Your All-in-One AI-Powered Toolkit for Academic Success.

Available 24*7 on WhatsApp / Email

[object Object]