#!/usr/bin/perl $numquestions = 10; $base = "/home/jordanrg/public_html/quizzes"; $class = "phy2044"; $qnum = 1; # $cgibase="http://courses.science.fau.edu/~rjordan/quizzes"; $cgibase="http://cosweb1.fau.edu/~jordanrg/quizzes"; require "/home/jordanrg/public_html/cgi-lib.pl"; &ReadParse(*input); if ($input{'class'}) { $class = $input{class}; } if ($input{'qnum'}) { $qnum = $input{qnum}; } if ($input{'numquestions'}) { $numquestions = $input{numquestions}; } # inhale the data file for this quiz $qfile = "$base/$class/quiz$qnum"; open FILE, $qfile; @inp = ; while ($inp = shift @inp) { if ($inp =~ /^\s*Q:/) { # if input matches Q for question $fqnum ++; # sequence num of filed questions $inp =~ s/^\s*Q:\s*//; $fqtxt[$fqnum] = $inp; # file question text $inp2 = shift @inp; while (($inp2 !~ /^(Q|[WR]A|C):/) && (@inp)) { $fqtxt[$fqnum] .= $inp2; $inp2 = shift @inp; } unshift @inp, $inp2; } if ($inp =~ /^\s*[WR]A:/) { # if input matches A for answer $fqlist[$fqnum] = $fqnum; # record question numbers for selection $fqalist{$fqnum}++; # count the number of answers for a question $inp =~ s/^\s*([WR])A:\s*//; $fqatxt{"$fqnum:$fqalist{$fqnum}"} = $inp; # file question answer text $fqacode{"$fqnum:$fqalist{$fqnum}"} = $1; # file question answer code $inp2 = shift @inp; while (($inp2 !~ /^(Q|[WR]A|C):/) && (@inp)){ $fqatxt{"$fqnum:$fqalist{$fqnum}"} .= $inp2; $inp2 = shift @inp; } unshift @inp, $inp2; } if ($inp =~ /^\s*C:/) { # if input matches C for comment if ($fqctxt{$fqnum}) { # if there is a comment already $inp =~ s/^\s*C:\s*//; $fqctxt{$fqnum} .= "
".$inp; # comment line 1
comment 2 } else { # otherwise, if no text already exists $fqctxt{$fqnum} = $inp; # text of comment } $inp2 = shift @inp; while (($inp2 !~ /^(Q|[WR]A|C):/) && (@inp)){ $fqctxt{$fqnum} .= $inp2; $inp2 = shift @inp; } unshift @inp, $inp2; } } close FILE; if ($fqnum < $numquestions) { $numquestions = $fqnum; } srand(time); # randomize based on the time for ($i = 0; $i < $numquestions; $i++) { $qn = int(1 + rand($#fqlist)); # set the question number $qout[$i] = $fqlist[$qn]; # grab question number $qn into the outlist splice @fqlist, $qn, 1, (); # removes element $qn from @fqlist } sub numerically { $a <=> $b } print &PrintHeader; $classhead = "$base/$class/class.head"; $classfoot = "$base/$class/class.foot"; $quizhead = "$base/$class/quiz$qnum.head"; $quizfoot = "$base/$class/quiz$qnum.foot"; open CH, $classhead; while ($inp = ) { $inp =~ s#\$(\w+)#${$1}#g; print $inp; } close CH; open QH, $quizhead; while ($inp = ) { $inp =~ s#\$(\w+)#${$1}#g; print $inp; } close QH; print "
\n"; $i = 0; foreach $qn (sort numerically @qout) { $i++; print "Q$i: $fqtxt[$qn]
"; print "$fqctxt{$qn}
"; for ($j=1; $j <= $fqalist{$qn}; $j++ ) { $ltr = chr(64 + $j); # do i need \" * 4 on the following? # if ($fqacode{"$qn:$j"} eq "R") { $ch = "CHECKED" } else { $ch = "" } print " "; print $fqatxt{"$qn:$j"}."
"; } print "\n"."

"; } open QF, $quizfoot; while ($inp = ) { $inp =~ s#\$(\w+)#${$1}#g; print $inp; } close QF; open CF, $classfoot; while ($inp = ) { $inp =~ s#\$(\w+)#${$1}#g; print $inp; } close CF; print <
END_OF_TEXT __END__ #for ($i = 1; $i < @qout; $i++) { # $qn = $qout[$i]; http://www.willcam.com/cmat/html/crossref.html print " CHECKED";