#!/usr/bin/perl # cgi script to add an entry to a survey # require("../../tracker/cgi-lib.pl") ; # &ReadParse(*in) ; # # input section ------- $q[0] = $in{'q1'} ; $q[1] = $in{'q2'} ; $q[2] = $in{'q3'} ; $q[3] = $in{'q4'} ; $q[4] = $in{'q5'} ; $nques = 5 ; $survey = "survey.dat" ; $home = "http://www.colby.edu/chemistry/OChem/CH242/Laboratory.html" ; # print "Content-type: text/html\n\n" ; print "Survey Update\n" ; print "\n" ; print "

Survey Update

\n" ; # insert entry # rename the file to saving.html, which can be used to recover from errors if (!rename($survey,"saving.dat")) { print "Couldn't save backup file.\n\n" ; exit } if (!open(ARC,"saving.dat")) { print "Couldn't open saved backup file saving.dat\n\n" ; exit } chmod 0766, "saving.dat" ; if (!open(OUT,">".$survey)) { print "Couldn't open file $survey\n\n" ; exit } $i = -1 ; while () { chop ; $i++ ; if ($i == $nques) { print "Too many questions in file.\n\n" ; exit } @a = split ; $a[$q[$i]]++ ; for ($k=0 ; $k<$nques ; $k++) { print OUT "$a[$k] " } print OUT "\n" ; } ; # end while ARC # close(OUT) ; chmod 0766, $survey ; # # finish off html on-the-fly page print "Thank you very much. Your survey entry has been added.

\n" ; print "" ; print "Click here to return to the course home page
\n" ; print "\n" ;