Thu Oct 28 19:00:00 EST 1999
Mastering the World-Wide Web
Fall99 - Midterm Examination
1. (10 points) Write a Perl program that opens a text file and prints the contents of the file to the standard output such that all vowels (uppercase or lowercase) are surrounded by parentheses. Here's an example assuming the program is called one and that it always opens the file called file, whose contents is also shown below.
one
file
school.cs.indiana.edu%cat file If a packet hits a pocket on a socket on a port, and the bus is interrupted and the interrupt's not caught, then the socket packet pocket has an error to report. -- Programmer's traditional nursery rhyme. school.cs.indiana.edu%./one (I)f (a) p(a)ck(e)t h(i)ts (a) p(o)ck(e)t (o)n (a) s(o)ck(e)t (o)n (a) p(o)rt, (a)nd th(e) b(u)s (i)s (i)nt(e)rr(u)pt(e)d (a)nd th(e) (i)nt(e)rr(u)pt's n(o)t c(a)(u)ght, th(e)n th(e) s(o)ck(e)t p(a)ck(e)t p(o)ck(e)t h(a)s (a)n (e)rr(o)r t(o) r(e)p(o)rt. -- Pr(o)gr(a)mm(e)r's tr(a)d(i)t(i)(o)n(a)l n(u)rs(e)ry rhym(e). school.cs.indiana.edu%
grep
two
packet
school.cs.indiana.edu%./two packet file If a (packet) hits a pocket on a socket on a port, then the socket (packet) pocket has an error to report. school.cs.indiana.edu%
A348:dgerman:Adrian German:Franklin M005:5-2510 A346:kinzler:Steve Kinzler:LH 430B:5-3478 A202:asengupt:Jit Sengupta:LH 225B:5-3703 A592:sebroadl:Sean Broadley:Sycamore 910:5-6663
Course name (e.g., A348) Press to search.
Press to search.
Your search for A348 produced the following result: A348 dgerman Adrian German Franklin M005 5-2510
<hr>
4. (10 points) Draw a diagram of your Apache web server directory structure and clearly identify on the diagram the following files (or write the absolute path for each one of them):
httpd.conf
User nobody
-rwx------ 1 username students 192 Sep 15 01:32 script
#!/usr/bin/perl print "Content-type: text/html\n\nHello world!";
6. (7 points) Explain what the following lines of perl do:
perl
open (AB, "datafile"); @lines = <AB>; foreach $line (@lines) { ($a, $b) = split(/:/, $line, 2); open (MAIL, "| mail $a\@indiana.edu"); print "$a:\n"; print "This message is for you."; close(MAIL); } close(AB);
datafile
7. (2 point) Which file contains the port number on which the server runs?
8. (2 point) The CGI specifies an interface whereby a CGI script called with method POST should expect to receive the data from the server in _________________
9. (2 point) The CGI specifies an interface whereby a CGI script called with method GET should expect to receive the data from the server in _________________
10. (6 points) Assume the following program:
#!/usr/bin/perl $x = $ARGV[0]; while ($x =~ s/([^a-z]+)//) { $i += 1; print "(", $i, ".: ", $1, ")\n"; }
./program "Thu Oct 28 15:59:59 EST 1999 Dow closed 10.22 higher"
^
11. (3 points) Explain what the following perl program (called prog) does:
prog
#!/usr/bin/perl print $ARGV[1] + $ARGV[0] + $#ARGV;
./prog 1 2 3 4 ./prog 5 10 ./prog one two
./prog 1 2 3 4
./prog 5 10
./prog one two
12. (10 points) Write the code for a JavaScript program that keeps track of how many times a button is pressed in a form on a web page and prints that to the user, somewhere where the user can see it.
13.1 (15 points) Write a simple calculator with JavaScript. The set up is as follows: the screen is split in two frames, one that has the add, sub, div and mul buttons, and a text field for the number (arg) that is to be added, subtracted, multiplied or used to divide the accumulator, and the other frame reports the current value of the accumulator (originally 0).
add
sub
div
mul
arg
0
13.2 (10 points) When the user is done computing a Proceed button should generate (either in one of the frames or in a separate window) an HTML form that contains:
Proceed
14. (3 points) Let's say you want to schedule a certain command (starthttpd -r) to run every day at 5am, but on Fridays you want it to run every 4 hours, and on the 1st and the 15th of each month you want it to run every hour. How would you set your crontab file?
starthttpd -r
5am
4
1
15
crontab
15. (3 points) Describe how you can start, stop, and/or restart the server without the use of starthttpd. The correct answer to this question would include
starthttpd
16. (3 points) Consider the following JavaScript code:
function a(x, y) { return x(y, y); } function b(x, y) { return x * y; } document.write(a(b, b(2, 3)));
Here is the exam with solutions