This is a prototype question containing both counting and logging of student activity. The student's wrong answers are recorded in a Master_student.dat file contained permanently in the public_html subdirectory.
The complete record of the student's activities are recorded in the Master_teacher.dat file in the same directory. It is the intention at this time of writing that this file be emptied once a year.
The Master_student.dat file only contains wrong answers. The Master_teacher.dat file contains, in one line, the student's and teacher's names, the right answer, and (possibly) the wrong answer. In addition, the time is recorded.
All the recording is done in a subroutine, so that we can globally change the reporting without changing individual question items, if people decide that the reports are ill conceived.
Note that the ultimate intention is to write reports off of these files, with the possibility of mailing them to repective faculty each nite (or once a week), etc., electronically.

#!/usr/local/bin/perl -- -*-perl-*-
use CGI;
$query = new CGI;
print $query->header;
print $query->start_html('Prototype Question_3-Logging');
require  "/home/cdavid/public_html/cgi-bin/CleanUp.pl";
require  "/home/cdavid/public_html/cgi-bin/explain.pl";
require  "/home/cdavid/public_html/cgi-bin/count.pl";
require  "/home/cdavid/public_html/cgi-bin/reports.pl";
srand;

$scriptname = $query->script_name();#this gives the question name
#print $query->dump;#use this to check that it worked! Just remove comment(#).

print "<a href=/~cdavid/cgi-bin/test_send_memo.pl?var=$scriptname>Click here to send a message concerning errors in this question.<br></a>";

# this question was called via html?owner=Jones&name=SomeOne
#$faculty_id = $query->param('faculty');
#$student_id = $query->param('student');
#print "<br>FACULTY(owner) = $query->param('owner'), STUDENT(owner) = $query->param('name')<br>";
print "<a href=../send_memo.html>Click here to get a notation explanation</a>";
#print $query->dump;
print "<br>";
&count($scriptname);
print $query->start_form;
print $query->hidden('faculty',$query->param('owner'));
print $query->hidden('student',$query->param('name'));
#print $query->dump;
$faculty_id = $query->param('faculty');
$student_id = $query->param('student');
print <<EOF;
This is teacher created text concerning this particular question.
Without explicit print statements, it must be entered using a
special format.
EOF
print "<br>Answer = ",$query->textfield('ans','',50,80);
print"<P> Query, is the above formula/number correct?",$query->submit;
print $query->end_form;
if ( $query->param('ans') ne '')
{
$faculty_id = $query->param('faculty');
$student_id = $query->param('student');
#print $query->dump;
#print "<br>student_id = ",$student_id;
$stu_ans = $query->param('ans');
$saved_stu_ans = $stu_ans;
&CleanUp($stu_ans);#this removes potential hacker imbedded illegal commands
$ans = "sqrt(4/x)"; 
$saved_ans = $ans;
$x = rand;
$ans =~s/x/$x/gi;
$stu_ans =~s/x/$x/gi;
print "student_answer = $saved_stu_ans";
$stu_ans = eval($stu_ans);
$ans =  eval($ans);
#print "student_answer  = $stu_ans <p>";
#print "student_answer evaluated = $stu_ans<p>";
#print "answer evaluated = $ans <p>";
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if (eval (($stu_ans - $ans)**2 - 0.0001  ) ge 0.0 ) {
	&reportstudent($faculty_id,$student_id,$saved_stu_ans,$saved_ans,$scriptname);	
	&reportfaculty($faculty_id,$student_id,$saved_stu_ans,$saved_ans,$scriptname);	
print ", <EM> Wrong</EM>,
	<IMG SRC=../icons/checkno.gif>"}
 else {print ", <EM> Right! </EM>,
	<IMG SRC=../icons/check.gif>" ;
	&reportfaculty_right($faculty_id,$student_id,$saved_stu_ans,$saved_ans,$scriptname);	
	}
};

print $query->end_html;
By keeping the reporting files separate, as subroutines, we are able to change the reporting scheme without bothering individual questions. Here are the contents of the reports.pl file:
#!/usr/local/bin/perl
sub reportstudent{
#report_student($faculty_id,$student_id,$saved_stu_ans,$saved_ans,$scriptname);	
%weekday=(
	"0","Sunday",
	"1","Monday",
	"2","Tuesday",
	"3","Wednesday",
	"4","Thursday",
	"5","Friday",
	"6","Saturday");
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
	open (STUD,">>/home/cdavid/public_html/Master_student.dat")||die 
		print "<br> Master_student.dat, Student File troubles Enountered, please report to instructor";
	print STUD "<$_[1]>=>q=$_[4]=A wrong student answer = ",$_[2]," versus corrrect answer = ",$_[3];
	close (STUD);
}
return -1;
sub reportfaculty{
%weekday=(
	"0","Sunday",
	"1","Monday",
	"2","Tuesday",
	"3","Wednesday",
	"4","Thursday",
	"5","Friday",
	"6","Saturday");
#report_student($faculty_id,$student_id,$saved_stu_ans,$saved_ans,$scriptname);	
	open (FACULTY,">>/home/cdavid/public_html/Master_teacher.dat")||die print 
		"<br> Master_teacher.dat, Faculty File Troubles Encountered, please report to instructor";
	print FACULTY "<$_[0]>=>q=$_[4]=student= ",$_[1]," entered a wrong answer ",
	$_[2]," versus the corrrect answer = ",$_[3],qq/$hour hours, $min minutes, $weekday{"$wday"},$mon,$mday, 19$year
/;
	close(FACULTY);
}

return -1;


sub reportfaculty_right{
%weekday=(
	"0","Sunday",
	"1","Monday",
	"2","Tuesday",
	"3","Wednesday",
	"4","Thursday",
	"5","Friday",
	"6","Saturday");
#report_student_right($faculty_id,$student_id,saved_stu_ans,$saved_ans,$scriptname);	

	open (FACULTY,">>/home/cdavid/public_html/Master_teacher.dat")||die print 
		"<br> Master_teacher.dat, Faculty File Troubles Encountered, please report to instructor";
	print FACULTY "<$_[0]>=>q=$_[4]=student= ",$_[1]," entered a correct answer = $_[2]", "<$_[0]>=>student= ,$_[1]",qq/$hour hours, $min minutes, $weekday{"$wday"},$mon,$mday, 19$year
/;
	close(FACULTY);
}
return -1;
</pre>

We are going to finish this prototypical examination question by adding a comment field, so that students can write a comment to their teacher (rather than to me, the examination files' maintainer). This will allow the student to complain about the question, or state some assumptions which are different from the one's that lead to the `correct' answer.

We also are going to add a link to a help file in the `Wrong!' branch, which will allow us to offer help when and where it is required.