CSCI 4230.1
Internet Application Development
Summer 2001
Mid-Term ExaminationName: _________________________________
Time allowed: one hour and 30 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. Plan your time well.
Academic honesty policy will be followed strictly. Cheating will result in a failing grade and a permanent academic record.
Total score: 100%.
(1) (25%) Write a Perl program t1aq1.pl to fetch a home page by a user specified URL in the command line argument and print out the counts of all image URLs referred in the page.
For example, executing the program:
t1aq1.pl http://www.sun.com
should output:
Images found in http://www.sun.com:
/2001-0612/hp0612.gif: 1.
/images/home/count.gif: 1.
/pics/dot.gif: 9.
/pics/fade.gif: 2.
/pics/home/head-sunpresents.gif: 1.
/pics/home/routers_us2.gif: 1.
/pics/sunlogo.gif: 1.For example, note that the image /pics/dot.gif appears 9 times in the page http://www.sun.com. Stick to the format above as close as possible. There are two spaces before each image line.
The image URL can be obtained from the src attribute value of the img tag. Note that HTML attribute values may be enclosed by ' or ".
(2) (3 questions: 25%)
(a) (5%) What is the output of executing the following Perl command line statement?
perl -e "@n = (10, 7, 13, 5); sort @n; print @n);"
(b) (5%) What is the output of executing the following Perl command line statement?
perl -e "print [1, 2, 3];"
(c) (15%) Write Perl code to print out all unique values of the hash %h. For example, if %h is defined as:
%h = (a => 1, b => 2, c => 3, d => 1, e => 2, f => 1);
your code should output:
1
2
3Duplicate key values are printed out only once. Your code should work with any value of %h, not just the one above.
(3) (25%) Write a simple Perl-CGI program, t1aq2d.pl, to display all values of user parameters of the format: user{ddd} where ddd is a sequence of one or more digits.
For example, if the URL is:
http://.../t1aq2d.pl?user1=yue&user3=davari&food=pizza&user12=perkins
the output is exactly:
![]()
Note that the HTTP parameter food is not displayed.
If the URL is:
http://.../t1aq2d.pl?food=pizza
the screen display is exactly:
![]()
(4) (25%) Write a simple CGI-Perl program t1aq4.pl which counts the number of spaces in the text the user submits. The program should initially display a form for the user to submit some text:
![]()
Note that the three lines of user input has 12 spaces in total. When the "submit query" button is clicked, the following result page should be displayed:
![]()