CSCI 4230.1
Software Tools
Spring 2001
Mid-Term Examination

Name:  _________________________________

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.  Plan your time well.
Total score: 100%.

(1)    (20%)  Write a simple Perl program t1aq2.pl to accept a command line argument which is an URL.  The program fetches the URL page and prints out all lines starting from the line containing the <body> tag and ending with (and including) the line containing the </body> tag.  There is no need to handle any kind of errors.  For example:

t1aq2.pl http://nas.uhcl.edu/yue/index.html

prints out every line in http://nas.uhcl.edu/yue/index.html from the line containing the <body> tag to the line containing the </body> tag.

(2)    (4 questions: 45%)

(a)    (5%)  What is the output of executing the following Perl command line statement?

perl -e "$a = (['a', 'b', 'c']); print $a;"
 

(b)    (20%) Write a Perl function extract($queryString) to accept a HTTP query string and return a hash of the name-value pair without performing URL decoding.  There is also no need to handle multi-valued HTTP parameters.  For example: extract("name=Bun+Yue&food=ice+cream&to=search") returns the hash:

(name=>'Bun+Yue', food=>"ice+cream", to=>"search");

(c)    What does the following Perl program print out (8%)?

$_ = '123abc11d';
/.+?(\d+)/;
print $1;
 

(d)    (12%) Consider the following HTML file from the URL:

http://dcm.uhcl.edu/someone/test/t1a.html

<html>
<body bgcolor="#ccccff">
<form method="get" action="somepgm.pl">
<input type="text" name="name">
<br>
<input type="hidden" name="money" value="talk">
<input type="submit">
</form>
</body></html>

It displays the form:

If "Bun Yue" is entered in the text field and the form is submitted, what will be the url (including the query string, if any) submitted.

(3)    (35%)  Write a CGI program t1q4.pl using CGI.pm, DBI and DBD::ODBC.  The CGI program takes a HTTP parameter 'division' and lists the total number of majors for the division and the numbers of majors for all programs within the division.  It uses the table t1aq4 (in the database with DSN demo) with the attribute "Program" being the primary key.  An instance of t1aq4 may look like:
 
Division Program NumberOfMajors
DVM  Computer Science 355
DVM Computer Information Systems 278
DVM Computer Engineering 40
DVM Software Engineering 45
FS Finance 79
NS Biology 55
NS Chemistry 15

If the CGI program is accessed by:

http://.../t1aq4?division=DVM

the following page should be displayed by the program using the table instance above:

Write your program to display the output page as close to the above as possible.  The order of the program is not important.