#!/opt/gnu/bin/perl use CGI qw(:standard); print header; my $ssn = param('ssn'); if ($ssn) { &print_result_page($ssn); } else { &print_initial_page; } exit 0; sub print_result_page { my $ssn = shift; my @title = (); my @grade = (); my $line; my $in_ssn; my $found; my $infile; print start_html('Grade Results'), h2('Result of your grades'), p; $infile = path_translated(); # For Windows directory. $infile =~ /(.*)\\/; $infile = $1 . "\\" . "grade.txt"; print $infile; open(IN, $infile); $line = ; @title = split /,/, $line; shift @title; # Remove SS#. # Search the ssn in the grade file. $found = 0; while ($line = ) { ($in_ssn, @grade) = split /,/, $line; if ($ssn eq $in_ssn) { $found = 1; last; } } if ($found) { print p, ""; # print title. foreach (@title) { print ""; } print ""; foreach (@grade) { print ""; } print "
$_
$_
"; } else { print "Sorry, SS Number $ssn not found."; } print end_html; } sub print_initial_page { print start_html('Check your grade'), h2('Check Your Grade'), p, "You can check your grade here!", &print_form; print end_html; } sub print_form { print p, start_form, "Type in your social security number, 9 digits without -.\n", p, "Your social security number:   ", textfield(-name=>'ssn', -size=>9), p, submit('Get Grades'), end_form; }