CSCI 4230.1
Internet Application Development
Fall 2000
Mid-Term ExaminationName: _________________________________
Time allowed: one hour and 20 minutes.
Open: text book, lecture notes, every file I posted in my web page and your project assignments.
Answer all questions. Turn in both questions and answer sheets.
Total score: 32%(1) Show the output of executing the following Perl program (6%):
(a) (2%)
my $arr = [1, 2, 4, {'a'=>5, 'b'=>7}, "lucky", []];
my $ele = @$arr;
print $ele;(b) (2 %)
$_ = "abcaacbccc";
/(.*)c/;
print $1;(c) (2%)
my @a = (1, 4, 7, 10, 13);
foreach (reverse sort @a) {
print "$_ ";
}(2) Write a program q2a.pl to parse an input file and generate an output file summarizing the input file. (10%)
The input file stores one student per line in the following format:
columns 1-19 Name
columns 20-29 Major
colums 30-41 Status
columns 42-45 GPAThe field status is always enclosed by a pair of double quotes.
Your program write the number of students for each major and status to the output file.
For example, for the input file q2a.txt
Kwok-Bun Yue CSCI "Senior" 3.35
Joe Giarratano CSCI "Senior" 3.75
Kathy Morning CIS "Junior" 3.35
Mary Post CSCI "Junior" 1.77
Boy George CSCI "Junior" 1.44
Fuji Appleton CIS "Freshman" 3.33
Kobe Bryant CSCI "Junior" 1.77and running your program as:
q2a.pl q2a.txt q2aout.txt
the output file q2aout.txt should be:
Number of students per major and status:
CIS Freshman: 1
CIS Junior: 1
CSCI Junior: 3
CSCI Senior: 2Your output file should use the format above exactly. Marks will be deducted for any discrepancy.
(3) Convert the following HTML code to use inline styling (3%):
<i><font face="Arial" size="36pt" color="blue">hello</font></i>
(4) Write the body of the function sourceHTML to make the following CGI/Perl program (t1aq4.pl) works. The program initially shows a form for the user to submit an URL through the HTTP parameter 'url'. It then shows the source code of the URL by printing the return string of calling sourceHTML($url), where $url stores the submitted URL string. (12%)
For example, for the input screen:
![]()
Assuming that the content of http://lattes.uhcl.edu/yue/f00/t1aq4.html is:
<html>
<head>
<title>My Hobbies</title>
</head>
<body bgcolor="#ccccff">
<h1>Example Page</h1>
<ul>My hobbies
<li>Eating
<li>Sleeping
<li>Watching TV
</ul>
</body>
</html>The result screen will be:
![]()
Note that extra spaces are removed in the display. Note also that the source code has a border and a background color of "#ccccff".
If the URL is not accessible, a proper message should be returned by sourceHTML.
![]()
The program t1aq4.pl:
use strict;
$|++;
use CGI;
use LWP::Simple;my $q = new CGI;
my $url = $q->param('url');if ($url) {
print sourceHTML($url);
}
else {
print initialForm();
}
exit 0;sub initialForm {
my $result = $q->header() .
$q->start_html("Source Code of HTML") .
$q->start_form() .
$q->h2("Source Code of HTML") .
$q->p("Input an URL to see the source code") .
$q->start_form() .
$q->textfield(-name=>'url', -size=>'50', -maxlength=>'130') .
$q->br() .
$q->submit() .
$q->end_form() .
$q->end_html();
$result;
}# Write your code for the subroutine sourceHTML here.
Hints: A '<' is interpreted by the browser as the beginning of a tag. Thus, to show the character '<', you need to use the entity reference '<'. In the same token, a '&' must be converted to '&'.