Reporting subroutines
Both subroutines discussed here are stored in one file, called report.pl.
Here, first, the is the standard report of student activity.
This subroutine is called when students get an answer wrong.
[ 1]#!/usr/local/bin/perl
[ 2]sub reportstudent{
[ 3]#report_student($faculty_id,$student_id,$saved_stu_ans,$saved_ans,$scriptname);
[ 4]# 0 1 2 3 4
Lines [3] and [4] show the order of arguments, and their position numbers,
which is useful when one has forgotten them.
[ 5]%weekday=(
[ 6] "0","Sunday",
[ 7] "1","Monday",
[ 8] "2","Tuesday",
[ 9] "3","Wednesday",
[10] "4","Thursday",
[12] "5","Friday",
[13] "6","Saturday");
&weekday is a kind of dual array, in which each element is doubled, with
one half being an integer and the other half being a textual element.
[14]($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
localtime is a system subroutine which decodes the time from its internal Unix
format, and assigns the output to the various variables listed on the left hand
side of the '=' sign.
Most of the variables are self explanatory.
[15] $question = $_[4];
This was passed in the argument string, and listed as the 5'th element, i.e.,
number 4 starting at zero.
[16] $question = substr($question,17);
This is not a good way to do what's being done, but at the time I was
quite naive.
What we want is to strip off the leading path information, and this worked.
Today, I would do this differently, but, perhaps one should leave this
as an exercise for the interested student.
[17] $l = length($question);
[18] $question = substr($question,0,$l-3);
Here, we strip off the '.pl' at the end of the file name, leaving
just the name of the question itself.
[19] $filename = "Wrong.".$_[0].".".$question.".dat";
In our case, we establish a file labelled with the name of the instructor,
$_[0], labelled with the question's name, $question, and labelled
with the 'Wrong' prefix so that we know that an entry here indicates
that the student got the answer wrong.
You, of course, can choose to do differently, and I think I would choose
now, in retrospect, to do differently, but, that was my choice many
years ago.
[20] open (STUD,">>../$filename")||die
[21] print "
$filename , Student File troubles Enountered, please report to instructor";
We open the file for appending, i.e., for writing on the end of the existing
file, adding the newest record.
If something goes wrong, we write a message and quit.
[22] flock ( STUD, 2);
We lock the file, so that no one else can use it until we are done.
[23] print STUD "Student = $_[1] WRONG ANS = ",$_[2]," RIGHT ANS = ",$_[3],"
";
We write a sentence into the file, indicating the student's name, the wrong
answer that was given, the right answer, and a carriage return, so that
we can have each line seen easily.
[24] close (STUD);
[25]}
[26]return -1;
Finally, we close the file and exit.
The rest of this file contains other report writers which
may or may not be of interest.
They all work the same way.
[27]sub reportfaculty{
[28]%months=(
[29] "0","Jan",
[30] "1","Feb",
[31] "2","Mar",
[32] "3","Apr",
[33] "4","May",
[34] "5","June",
[35] "6","July",
[36] "7","Aug",
[37] "8","Sep",
[38] "9","Oct",
[39] "10","Nov",
[40] "11","Dec");
[41]%weekday=(
[42] "0","Sunday",
[43] "1","Monday",
[44] "2","Tuesday",
[45] "3","Wednesday",
[46] "4","Thursday",
[47] "5","Friday",
[48] "6","Saturday");
[49]($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
[50]#report_student($faculty_id,$student_id,$saved_stu_ans,$saved_ans,$scriptname);
[51] $question = $_[4];
[52] $question = substr($question,17);
[53] $l = length($question);
[54] $question = substr($question,0,$l-3);
[55] $filename = "Wrong.".$_[0].".".$question.".dat";
[56] open (FACULTY,">>../$filename")||die print
[57] "
Faculty File Troubles Encountered, please report to instructor";
[58] flock ( FACULTY, 2);
[59] print FACULTY "fac= $_[0] q=$question stud= ",$_[1]," WRONG=",
[60] $_[2]," ANS= ",$_[3],qq/ $hour:$min $weekday{"$wday"} $months{"$mon"} $mday, 19$year
/;
[61] close(FACULTY);
[62]}
[63]return -1;
Here is the reportfaculty_right subroutine, which is called when students
get an answer correct.
[64]sub reportfaculty_right{
[65]%weekday=(
[66] "0","Sunday",
[67] "1","Monday",
[68] "2","Tuesday",
[69] "3","Wednesday",
[70] "4","Thursday",
[71] "5","Friday",
[72] "6","Saturday");
[73]%months=(
[74] "0","Jan",
[75] "1","Feb",
[76] "2","Mar",
[77] "3","Apr",
[78] "4","May",
[79] "5","June",
[80] "6","July",
[81] "7","Aug",
[82] "8","Sep",
[83] "9","Oct",
[84] "10","Nov",
[85] "11","Dec");
[86]($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
987]#report_student_right($faculty_id,$student_id,saved_stu_ans,$saved_ans,$scriptname);
[88] $question = $_[4];
[89] $question = substr($question,17);
[90] $l = length($question);
[91] $question = substr($question,0,$l-3);
[92] $filename = "Right.".$_[0].".".$question.".dat";
[93] open (FACULTY,">>../$filename")||die print
[94] "
$filename , File Troubles Encountered, please report to instructor";
[95] flock ( FACULTY, 2);
[96]
[97] print FACULTY "fac= $_[0] q=$question stud= ",$_[1]," RIGHT =",
[98] $_[2],qq/ $hour:$min $weekday{"$wday"} $months{"$mon"} $mday, 19$year
/;
[99] close(FACULTY);
[100]}
[101]return -1;
Here is a (unused subroutine) which reports help.
[ ]sub reporthelp{
[ ]%weekday=(
[ ] "0","Sunday",
[ ] "1","Monday",
[ ] "2","Tuesday",
[ ] "3","Wednesday",
[ ] "4","Thursday",
[ ] "5","Friday",
[ ] "6","Saturday");
[ ]%months=(
[ ] "0","Jan",
[ ] "1","Feb",
[ ] "2","Mar",
[ ] "3","Apr",
[ ] "4","May",
[ ] "5","June",
[ ] "6","July",
[ ] "7","Aug",
[ ] "8","Sep",
[ ] "9","Oct",
[ ] "10","Nov",
[ ] "11","Dec");
[ ]($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
[ ]#reporthelp(faculty_id,$student_id,$scriptname);
[ ] $question = $_[4];
[ ] $question = substr($question,17);
[ ] $l = length($question);
[ ] $question = substr($question,0,$l-3);
[ ] $filename = "Help.".$_[0].".".$question.".dat";
[ ]
[ ] open (FACULTY,">>../Master_teacher.dat")||die print
[ ] "
Master_teacher.dat, Faculty File Troubles Encountered, please report to instructor";
[ ] flock ( FACULTY, 2);
[ ] print FACULTY "fac = $_[0] q=$question stud= ",$_[1]," HELP ",qq/ $hour:$min, $weekday{"$wday"}, $months{"$mon"} $mday, 19$year
/;
[ ] close(FACULTY);
[ ]}
[ ]return -1;
Last edit: 8hrs:25min, Friday, August 14, 20120