#!C:/perl/bin/perl.exe
use CGI::Carp qw(fatalsToBrowser);
use CGI;
$query = new CGI;
# Demonstration of how to use a Perl script to administer the survey
# Import information from CGI data packet
$v01= $query->param('v01');
$v02= $query->param('v02');
$v03= $query->param('v03');
$v04= $query->param('v04');
$v05= $query->param('v05');
# Import the value of pass. If it doesn't exist, Perl will answer TRUE to $pass < 1. Thus, we use this test to assign an explict value of 0 to $pass if the script has not been activated
$pass= $query->param('pass');
if($pass < 1){
$pass=0;
}
# Obtain current date and time from server
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = 1900 + $year;
$mon= $mon+1;
$hour = $hour - 1;
$date1= "$mon/$mday/$year";
$date2= "$hour:$min:$sec";
# Prepare to send HTML code to browser
print $query->header;
print $query->start_html(-title=>'Thank You');
# Create styles
print "";
# This part is just for testing purposes
print "Script Test: The scores thus far are v01=$v01, v02=$v02, v03=$v03, v04=$v04, and v05=$v05.
";
# Execute the block of code below if pass equals 1 (i.e., second time the user activates the script)
# Important note: We execute the pass=1 block BEFORE the pass==0 block.
if($pass == 6){
# Compute a composite score (average the responses to all the items)
$esteem = ($v01 + $v02 + (6-$v03) + $v04 + (6-$v05))/5;
$esteem2 = sprintf("%.2f",$esteem);
# Open the data file and append the new data to the last row
open(INFO, ">>$ENV{'DOCUMENT_ROOT'}/P593/form3.txt");
print INFO "$date1,$date2,$v01,$v02,$v03,$v04,$v05,$esteem2,endline\n";
close (INFO);
# Open the data file and dump its contents to @data
open(INFO, "$ENV{'DOCUMENT_ROOT'}/P593/form3.txt");
@data = ;
close(INFO);
# Provide feedback
print "Thank you for your participation. Your self-esteem score is $esteem2 on a scale ranging from 1 (low) to 5 (high).
";
} # end pass = 1
if($pass == 5){
print "";
}
if($pass == 4){
print "";
}
if($pass == 3){
print "";
}
if($pass == 2){
print "";
}
if($pass == 1){
print "";
}
# Execute the block of code below if pass equals 0 (i.e., first time the user activates the script)
if($pass == 0){
print " Demonstration of how to deliver HTML in perlThis page is designed to assess your self-esteem.
Please answer the following questions. Once you have answered each question,
click the button labeled calculate my score. The web page will then calculate
your self-esteem score, and tell you more about how you compare to others.
";
} # end pass == 0
# Note the hidden tag that has been added to the code above
#
# This allows you to pass a variable along with the rest of the data, but in a way that
# is hidden to the user.
print $query->end_html;