Homework 6

Due at or before 7pm on Thursday Oct. 29, 1998.

1. Write the HTML for a table like this:
  +---+---+
  | 0 | X |
  +---+---+
  |   | X |
  +---+---+
Clarification note:
Use the <table> tag to create a 2x2 table (with border) in which the two cells on its right carry an X, the NW cell carries a 0, and one cell (SW) is empty.
Type your answer here:





2. What's the output for this simple Perl program:

#!/usr/bin/perl
$i = 0; $j = 1; 
if ($i = 2) { print $i; }
else { print $j; }

The answer is:


0
1
2
3


3. Which of the following is a valid way to embed an applet class named Q56 into a web page?

Select all right answers:

<applet class=Q56.class width=100 height=100>
</applet>
<applet code=Q56 width=100 height=100>
</applet>
<applet code=Q56.class width=100 height=100>
</applet>
<applet param=Q56.class width=100 height=100>
</applet>
<applet param=Q56 width=100 height=100>
</applet>

4. You're using GD.pm to draw pictures. What does the following code do (if anything):

$image->line(0, 10, 20, 30); 
draw a line from (0, 20) to (10, 30)
draw a line from (0, 10) to (20, 30)
draw the outline of a box whose left, top corner is at (0, 10) and that is 20 pixels wide and 30 pixels high
nothing - this code does not compile because it does not provide the correct number of arguments
nothing - this code does not compile because the arguments make no sense

5. JavaScript code appears in between <SCRIPT> and </SCRIPT> tags. Is it necessary that the JavaScript code be placed inside the <HEAD> </HEAD> section?


Yes, this is the required syntax, you have to do it this way.
JavaScript needs to compile before the HTML page is loaded.
It's not mandatory but it's good practive when using event handlers in web pages because objects that define event handlers need to appear inside <BODY> and </BODY>
No, you can place it anywhere in the file, it doesn't matter.


6. Your Apache directory structure looks like this:

/---u---username---httpd---+---httpd*
                           |
                           +--logs
                           |
                           +--cgi-bin
                           |
                           +--conf
                           |
                           +--src
                           |
                           ... 
Where is httpd.pid located:
/u/username/httpd/logs
/u/username/httpd/cgi-bin
/u/username/httpd/conf
/u/username/httpd/src

7. What does it contain?

Type your answer here:




8. Match the following configuration files with roles listed:

8.1 httpd.conf
controls the behaviour of the server after it starts up
provides directory-by-directory control over what hosts and users can retrieve documents from your server
controls settings that are used when the server first starts up
none of the above

8.2 srm.conf


controls the behaviour of the server after it starts up
provides directory-by-directory control over what hosts and users can retrieve documents from your server
controls settings that are used when the server first starts up
none of the above

8.3 access.conf

controls the behaviour of the server after it starts up
provides directory-by-directory control over what hosts and users can retrieve documents from your server
controls settings that are used when the server first starts up
none of the above

9. From /u/username/httpd/logs which of the following commands can be used to start your server (check all that apply).

starthttpd -k
/u/username/httpd/httpd -d /u/username/httpd
./httpd -d .
/u/username/httpd/httpd -d ..
none of the above


10. What's the output of this simple Perl program:

#!/usr/bin/perl
@a = ("camel", "bobac"); 
%a = ("camel" => "desert", "bobac" => "burrow"); 
print $a{$a[$a]}, "\n"; 

camel
desert
bobac
burrow


11. Assume this crontab entry:

0 * * * 1 /u/username/bin/starthttpd 
and a properly configured starthttpd.

Then your server will be checked and if needed restarted

every Sunday at midnight
every Sunday
every hour
every hour on Mondays only


12. Write an HTML form that contains:

Make the form point to
http://tucotuco:19800/cgi-bin/database
and set the request method to POST











13. Here's the tucotuco:19800/cgi-bin/database script:

#!/usr/bin/perl
use CGI;
$query = new CGI; 
$function = $query->param('function'); 
$animal   = $query->param('animal'); 
$habitat  = $query->param('habitat'); 
print $query->header, $query->start_html; 
dbmopen($zoo, "/u/username/databases/zoo", 0644); 
if ($function eq 'add') {
  if ($zoo{$animal}) { $zoo{$animal} .= ":$habitat"; } 
  else { $zoo{$animal} = $habitat; } 
  print "Thanks for adding ($animal, $habitat)"; 
} elsif ($function eq 'search') {
  print $zoo{$animal}; 
} else { print "Command $function not implemented yet."; } 
dbmclose(%zoo); 
print $query->end_html;
Assume that the database is empty and the script is called four times in this sequence:
  1. (Animal=camel, Habitat=desert, Function=add)
  2. (Animal=camel, Habitat=new york, Function=add)
  3. (Animal=camel, Habitat=desert, Function=add)
  4. (Animal=camel, Habitat=whatever, Function=search)
What will the screen look like after the fourth call:

desert
new york
new york:desert:desert
desert:new york:desert
:desert:new york:desert:


14. Which of the following files contains the number of the port on which the server runs?

httpd.pid
httpd.conf
access.conf
srm.conf
none of the above


15. The CGI specifies an interface whereby a CGI script called with method POST should expect to receive the data from the server in:

STDIN
$ENV{CONTENT_LENGTH}
$ENV{QUERY_STRING}
STDOUT
$QUERY_STRING

16. You have a text file (called one.csv) which contains lines of the following format:

camel,desert,new york,los angeles
bobac,burrow
moose,lindley hall,canada
Each line in the file starts with an animal and contains (separated by commas) habitats for that specific animal that is, places where the animal has been seen. Assume that for each animal there is only one line in the file that starts with that animal's name and that the line contains all habitats for that particular animal on that line, following the name, and separated by commas.

What will this program print:

#!/usr/bin/perl
$animal = $ARGV[0]; 
open (AB, "one.csv");
while ($line = <AB>) {
  if ($line =~ /^$animal,/) {
    print $line; # [1]
    exit; 
  } 
}
close(AB); 
print "Couldn't find $animal\n"; 
when called as follows:
./program camel
Write your answer here:


What will it print when called as follows:
./program CAMEL
Write your answer here:


Change line [1] (replace it with one or more lines of code) such that the habitats are listed each on a separate line, for example:
./program moose
prints
Subject: moose
Has been seen in: 
  - lindley hall
  - canada 
Write your answer here:





17. In JavaScript which of the following events apply to radio buttons:

onSubmit
onClick
onBlur
onFocus
onChange
onMouseOver
onLoad
Check all that apply.


18. Assume the following program:

#!/usr/bin/perl
$x = $ARGV[0]; 
while ($x =~ s/(\d+)//) {
  print ++$i, ". ", $1, "\n"; 
} 
What is the program going to print when called as follows:
./program "123 abc 12.13 ;m3p23"
Write your answer here:




19. The CGI specifies an interface whereby a CGI script called with method GET should expect to receive the data from the server in:

STDIN
$ENV{CONTENT_LENGTH}
$ENV{QUERY_STRING}
STDOUT
$QUERY_STRING

20. Write a program that receives two strings on the command line and removes all occurrences of the first string from the second one and then prints what's left of the second string.

For example:

tucotuco.cs.indiana.edu% ./program "a" "Friday Saturday Sunday"
Fridy Sturdy Sundy
tucotuco.cs.indiana.edu% ./program "ay" "Friday Saturday Sunday"
Frid Saturd Sund
tucotuco.cs.indiana.edu%
Write your answer here:







Posted: Friday Fri, 23 Oct 1998 22:25:15 -0500 (EST)
Minor layout adjustments: Sat Oct 24 16:18:33 EST 1998