CSCI 4230.1
Internet Application Development
Fall 2000
Suggested Solution to Mid-Term Examination

(1)

(a)    6
(b)    abcaacbcc
(c)    7  4  13  10  1

(2)    For example,

use strict;

@ARGV < 2 && die "Usage: t1q2.pl inputfile outfile\n";
open(IN, $ARGV[0]) || die "can't open input file $ARGV[0].\n";
open(OUT, ">$ARGV[1]") || die "can't open output file $ARGV[1].\n";

my %result = ();

while ($_ = <IN>) {
   chomp;
   my $major = substr($_, 19, 10);
   my $status = substr($_, 29, 12);
   $major =~ s/\s*$//;
   $status =~ s/\s*$//;
   $status =~ s/"//g;
   $result{"$major $status"}++;
}

print OUT "Number of students per major and status:\n\n";
foreach (sort keys %result) {
   print OUT "$_: $result{$_}\n";
}

exit 0;

(3)    For example,

<span style="font-family:Arial; font-style:italic; color:blue; font-size:36pt">hello</span>

(4)    For example,

sub sourceHTML {
   my $url = shift;
   my $urlContents = get($url);
   my $result = undef;
   if ($urlContents) {
      $result = $urlContents;
      $result =~ s/&/&amp;/g;
      $result =~ s/</&lt;/g;
      $result =~ s/\n/<br>/gm;
      $result = $q->p("Source code of $url:") .
                "<div style=\"background-color:#ccccff;border: 1px #000000 solid;padding:5px\">" .
                $result .
                "</div>";
   }
   else {
      $result = $q->p("The URL $url cannot be accessed.");
   }
 
   $q->header() .
   $q->start_html("Source Code of HTML") .
   $q->h2("Source Code of HTML") .
   $result .
   $q->end_html();
}