chriso has asked for the wisdom of the Perl Monks concerning the following question:
#!/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 brea +k 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 (<FILE>) { # ** 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 QUESTI +ON print "<B>$value</B><BR>"; local @allquestions = (@allquestions, $value); } if ($type =~ m/a/i) { # ** CHECKS FOR ANSWER LINE my @answers = split (/,/, $value); # ** SPLITS ANSWER LINE IN +TO ARRAY local $anslength = @answers; # ** LENGTH OF @ANSWERS local @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 CHECKB +OX print checkbox_group(-name=>$type, -values=>\@options, -linebre +ak=>'true', -labels=>\%selections); }else { print "<BR>"; print radio_group(-name=>$type, -values=>\@options, -linebre +ak=>'true', -labels=>\%selections, -default=>'-'); } print "<BR><HR><BR>"; } # END IF STATEMENT } # ** END WHILE STATEMENT close (FILE); print hidden(-name=>"answers", -default=>\@allanswers); print hidden(-name=>"questions", -default=>\@allquestions); print "<CENTER>"; print submit (-value=>'Grade') . " "; print reset (-value=>'Reset answers'); print "</CENTER>"; print end_form; print end_html;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: explicit package name
by Juerd (Abbot) on Dec 17, 2001 at 20:56 UTC | |
by tilly (Archbishop) on Dec 18, 2001 at 09:13 UTC | |
|
Re: explicit package name
by Hofmator (Curate) on Dec 17, 2001 at 22:36 UTC | |
|
Re: explicit package name
by Masem (Monsignor) on Dec 17, 2001 at 22:51 UTC |