Sample Perl Script

#!perl
use CGI;
$q = new CGI;
#get the parameters passed to the script
###################
$name = $q->param('name'); 
$testName = $q->param('TestName');
$numQuestions = $q->param('NumQuestions');
$passingGrade = $q->param('PassingGrade');
$score = $q->param('Score');
if( $testName eq "" || $numQuestions eq "" )
{
 print "Content-type: text/html\n\n";
 print "<html>";
 print "<head><title>Failure</title></head>";
 print "<body>";
 print "STATUS=500";
 print "<br>";
 print "Could not parse test results due to a parameter error.";
 print "</body></html>"; 
 exit 0;
}
##################### 
#get the current time
##################### 
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) 
= localtime(time);
$year = $year + 1900;
$mon = $mon + 1;
$currtime = "$year-$mon-$mday $hour:$min:$sec";
#####################
#opens test data file for append and write the data
##################### $testName .= ".log";
open( TESTDATA,">>c:\\$testName" ) or die;
print TESTDATA "$currtime $name $numQuestions $passingGrade $score\n";
#####################
# Older courses produced by the program used a zero based index for the 
questions (i.e. Question0 is the first question)' # Newer courses are one 
based (i.e. Question1 is the first question)'
# determine which one it is' 
##################### 
$startindex = 0;
$temp = $q->param('
Question0'); if( $temp eq 
"" )
{
 $startindex = 1;
}
$index = $startindex;
#####################
#Write out all of the questions and answers 
#####################
while( $index < ($startindex + $numQuestions) ) {
 $qst = "Question$index"; $ans = "Answer$index"; $qval = $q->param
 ( $qst ); $aval = $q->param( $ans );
 print TESTDATA "$qst: $qval\n";
 print TESTDATA "$ans: $aval\n";
 $index += 1;
}
close TESTDATA;
##################### #reply that it worked
#################### print $q->header();
print "STATUS=200\r\n";

Knowledge Base | Training | Support
© Copyright eLearning Brothers 2021