#!/usr/bin/perl #c:\sambar50\perl\perl.exe use CGI qw(:standard); use strict; use warnings; print header; local $/ = "~\n"; # *** CHANGES INPUT RECORD SEPARATOR TO ~line break print start_html (-title=>'quiz', -BGCOLOR=>'beige'); print start_form (-method=>'POST', -action=>"http://localhost/cgi-bin/gradequiz.cgi"); my $file = param('file'); open (FILE, $file) || die "Cannot open $file: $!"; while () { # ** READS EACH LINE OF TEXT FROM FILE chomp; # ** BY DEFAULT, CHOMPS OFF $/ FROM EACH LINE my ($type, $value) = split (/:/, $_); # ***** SPLITS EACH LINE BY TYPE AND CONTENT if ($type =~ m/q/i) { # ** CHECKS FOR QUESTION LINE & PRINTS QUESTION print "$value
"; @allquestions = (@allquestions, $value); } if ($type =~ m/a/i) { # ** CHECKS FOR ANSWER LINE my @answers = split (/,/, $value); # ** SPLITS ANSWER LINE INTO ARRAY $anslength = @answers; # ** LENGTH OF @ANSWERS @allanswers = (@allanswers, $value); } #** CHECKS FOR SELECTION LINE AND if ($type =~ m/^s/) { # ** TYPE OF ANSWER BOX my %selections = split (/,/, $value); my @options = keys (%selections); if ($anslength > 1) { # ** DETERMINES TO USE RADIO OR CHECKBOX print checkbox_group(-name=>$type, -values=>\@options, -linebreak=>'true', -labels=>\%selections); }else { print "
"; print radio_group(-name=>$type, -values=>\@options, -linebreak=>'true', -labels=>\%selections, -default=>'-'); } print "


"; } # END IF STATEMENT } # ** END WHILE STATEMENT close (FILE); print hidden(-name=>"answers", -default=>\@allanswers); print hidden(-name=>"questions", -default=>\@allquestions); print "
"; print submit (-value=>'Grade') . "   "; print reset (-value=>'Reset answers'); print "
"; print end_form; print end_html;