#!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 # Using a single script # 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 ""; # 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 == 1){ # 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 # 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 perl
This 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.

1. I feel that I'm a person of worth, at least on an equal plane with others.
Strongly Disagree Strongly Agree

2. I feel that I have a number of good qualities.
Strongly Disagree Strongly Agree

3. All in all, I am inclined to feel that I am a failure.
Strongly Disagree Strongly Agree

4. I am able to do things as well as most other people.
Strongly Disagree Strongly Agree

5. I feel I do not have much to be proud of.
Strongly Disagree Strongly Agree


"; } # 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;