#!/usr/bin/perl ################## script11.cgi #### Include the perl module CGI.pm use CGI qw( :standard); #### Extract values from form using param( ) function $report = param( "report" ); $username = param( "username" ); $password = param( "password" ); #### initialize flag $flag = 0; #### Html web page is coming print "Content-type:text/html\n\n"; #### Start of html for web page print "Geno Patterson -- perl grade report for assignment11 \n"; ### printing initial values for form elements #print "report = $report
"; #print "username = $username
"; #print "password = $password
"; #### Checkprint "in flag = 0 loop"; for password if($password ne "cs2378i"){ print "PASSWORD INVALID!!!! Please reenter the password.
"; $flag = 1; }## end password tprint "in flag = 0 loop";est #### check if at least one of the radio buttons are checked if(! $report){ print"ERROR!!! Please check report type (single student or all students)
"; $flag = 1; } #### check report for single if($report eq "single"){ if($username eq ""){ print "ERROR!!! You must specify the username of the student you want a report for.
"; $flag = 1; } } ## end curly for report-single test ### Test for flag to put in back link if($flag == 1){ ### link back to form print "
Click Here to go back to form to re-enter incorrect data
"; } #### trying to use grep if($flag == 0){ ### no errors encountered $datafile = "grades.csv"; $searchstring = $username; open(INF,$datafile); @mydata = ; close(INF); if($report eq "all"){ print ""; foreach $j (@mydata){ #print "
  • $j
    "; ($user, $last,$first, $h1, $h2,$h3,$h4,$h5,$h6, $h7,$h8,$h9,$h10,$havg, $lavg,$ex1,$ex2,$finex, $exavg,$finavg,$fingrade)= split(/,/, $j); #print "
  • user=$user"; #print "
  • last=$last"; print "
  • "; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; } print "
    $user$first$last$h1$h2$h3$h4$h6$h5$h6$h7$h8$h9$h10
    "; } else { @results = grep(/$searchstring/i,@mydata); if(@results ne ""){ print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print "
    $user$first$last$h1$h2$h3$h4$h6$h5$h6$h7$h8$h9$h10
    "; } #} else { print "Username not found please try again
    "; print "
    Click Here to go back to form to re-enter incorrect data
    "; } } }