chriso has asked for the wisdom of the Perl Monks concerning the following question:
******** CODE TO PRINT QUIZ
*** CODE TO GRADE QUIZ - THIS IS WHERE THE PROBLE IS.use CGI qw(:standard); print header; local $/ = "~\n"; $infile = param('file'); print start_html ( -title=>'quiz', -BGCOLOR=>'beige' ); print start_form ( -method=>'POST', -action=>"http://netlab/perl/obenberger/gradequiz.cgi" ); open (FILE, $infile) || die "Cannot open $infile: $!"; while (<FILE>) { chomp; ($type, $value) = split (/:/, $_); if ($type =~ m/q/i) { # ******* CHECKS FOR QUESTION LINE print "<B>$value</B><BR>"; } if ($type =~ m/a/i) { # ********* CHECKS FOR ANSWER LINE @answers = split (/,/, $value); $anslength = @answers; } if ($type =~ m/^s/) { # *** DETERMINES TYPE OF ANSWER BOX %selections = split (/,/, $value); @options = keys (%selections); if ($anslength > 1) { print checkbox_group(-name=>$type, -values=>\@options, -linebreak= +>'true', -labels=>\%selections); }else { print "<BR>"; print radio_group(-name=>$type, -values=>\@options, -linebreak=>'t +rue', -labels=>\%selections, -default=>'-'); } print "<BR><HR><BR>"; } } # ********** END WHILE STATEMENT close (FILE); print "<CENTER>"; print submit (-value=>'Grade') . " "; print reset (-value=>'Reset answers'); print "</CENTER>"; print end_form; print end_html;
********* DATAuse CGI qw(:standard); print header; print start_html (-title=>'graded quiz', -BGCOLOR=>'beige'); # The match doesn't work if more than one character is matched if(param('s1') =~ m/ad/i) { print "<B><BR>Correct! Congradulations! Your answer was a</B><P>"; }else{ print "<B><BR>Incorrect! You did not mark the correct answer!</B><P>"; } print "<BR>The value for s1 is: <B>"; print param('s1'); print "</B><P>"; print "The value for s2 is: <B>"; print param('s2'); print "</B><P>"; print "The value for s3 is: <B>"; print param('s3'); print "</B><P>"; print "The value for s4 is: <B>"; print param('s4'); print "</B><P>"; print "<HR>"; foreach $key (param()) { print "NAME = "; print $key; print " and VALUE = "; print param($key); print "<P>"; } print "<HR>"; # Only the first character of the value is printed. Why? foreach $key (param()) { print "NAME = " . $key . "and VALUE = " . param($key) . "<P>"; } print end_html;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Match function not providing results
by Corion (Patriarch) on Dec 14, 2001 at 19:23 UTC | |
by chriso (Sexton) on Dec 14, 2001 at 20:59 UTC | |
by Corion (Patriarch) on Dec 14, 2001 at 21:38 UTC | |
|
Re: Match function not providing results
by andye (Curate) on Dec 14, 2001 at 19:27 UTC | |
|
Re: Match function not providing results
by Steve_p (Priest) on Dec 14, 2001 at 19:49 UTC |