#!/var/local/couch/bin/perl
&header;
@contents = read_file("scores.txt");
&print_file(@contents);
&footer;
exit(0);

sub read_file{
my($name) = @_;
my (@FileInfo);
open (FILE, $name);
@FileInfo = <FILE>;
close(FILE);
return @FileInfo;
}

sub print_file
{
my(@contents) = @_;
my($element);
print "Here is everyone's information!:<p><I>\n";
$numLines=0;
foreach $element(@contents)
   {print "$element<BR>";
    $numLines++;}
print "</I>\n";
$numUsers=$numLines / 3;
$totalCorrect=0;
$Sum=0;
for ($j=2;$j<$numLines+2;)
  {
$Sum=$contents[$j]+$Sum;
$j=$j+3;
}
$Avg=$Sum / $numUsers;
print "<p>The average score on this test is: $Avg percent.<p>\n";
}

sub header
{# print the header for the HTML page
   print "Content-type: text/html", "\n\n";
   print "<HTML><HEAD><TITLE></TITLE></HEAD>\n";
   print "<BODY BGCOLOR = 'white'>\n";
}

sub footer
{# print the footer for the html page
   print "</BODY></HTML>";
}
