#!C:/perl/bin/perl.exe use CGI::Carp qw(fatalsToBrowser); use CGI; $query = new CGI; #-------------------------------------------- # Read in CGI data #-------------------------------------------- $v00= $query->param('v00'); $v01= $query->param('v01'); $v02= $query->param('v02'); $v03= $query->param('v03'); $v04= $query->param('v04'); $v05= $query->param('v05'); $pass= $query->param('pass'); if($pass<1){$pass=1;} #-------------------------------------------- # Basic Formatting and Style #-------------------------------------------- print $query->header; print $query->start_html(-title=>'page title'); #------------------------ # pass = 4 #------------------------ if($pass == 4){ # get date and time ($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"; $progcorr = &datacorr(2,3); # write data to text file open(INFO, ">>$ENV{'DOCUMENT_ROOT_OLD'}/www/p593/data/routinedata.txt"); print INFO "$v00,$v01,$v02,$v03,$progcorr,$date1,$date2,$v02,$v03,endline\n"; close (INFO); print "Your data have been saved. Thank you for your time.

"; print "Oh, and by the way, the correlation between responses on programming and responses on jogging for all the respondents is $progcorr." } # end pass = 4 #------------------------ # pass = 3 #------------------------ if($pass == 3){ print "
"; print "Please answer the following questions:

"; print "I am the kind of person who likes jogging.
"; &radiomaker('v03'); print ""; &passHidden; print ""; print "
"; } # end pass = 3 #------------------------ # pass = 2 #------------------------ if($pass == 2){ print "
"; print "Please answer the following questions:

"; print "I am the kind of person who likes programming.
"; &radiomaker('v02'); print ""; &passHidden; print ""; print "
"; } # end pass = 2 #------------------------ # pass = 1 #------------------------ if($pass == 1){ print "
"; print "Please enter your name:



"; print "Please enter your age:



"; &passHidden; print ""; print ""; print "
"; } # end pass = 1 #-------------------------------------------------------------- # for troubleshooting and programming - print all cgi data #-------------------------------------------------------------- $printAllCGI = 0; #******************************************************************************* if($printAllCGI == 1){ # Print all CGI data print "----------------dump all query -----
"; foreach $key (sort($query->param)) { $value = $query->param($key); print "$key = $value
"; } print "----------------------------
"; } print $query->end_html; #1. A routine that automatically creates the radio buttons #for items that require 1 to 5 rating scales. sub radiomaker { print "     Strongly Disagree "; print " "; print " "; print " "; print " "; print " "; print "Strongly Agree


"; } #2. A routine the passes all data from one page to the next #via hidden tags. sub passHidden { # This subroutine passes along all information (collected or not) in the form of hidden tags. This allows the information to be carried from one page to the next, despite the fact that the relationship between the subject and the server is "stateless." Instead of writing this out separately for each section of the code in which an item/stimulus is presented, we place the code in a subroutine and call this subroutine at each step along the way. # To customize: Create a hidden tag for each response in question. In the example, we have reponses to 5 self-esteem questions and some demographic items. print $query->hidden('varlistRandom',@varlistRandom); print ""; print ""; print ""; print ""; print ""; print ""; } #3. A routine that automatically opens the data file and #computes correlations between two variables. #first entry is index of x, second is index of y sub datacorr { $xindex = $_[0]; $yindex = $_[1]; open(INFO, "$ENV{'DOCUMENT_ROOT_OLD'}/www/p593/data/routinedata.txt"); @data = ; close(INFO); $sumx = 0; $sumy = 0; $sumx2 = 0; $sumy2 = 0; $sumxy = 0; foreach $key (@data) { @a = split(/,/,$key); $sumx = $sumx + $a[$xindex]; $sumy = $sumy + $a[$yindex]; $sumx2 = $sumx2 + $a[$xindex]**2; $sumy2 = $sumy2 + $a[$yindex]**2; $sumxy = $sumxy + ($a[$xindex]*$a[$yindex]); $n = $n + 1; } $corrxy1 = $sumxy - ($sumx*$sumy/$n); $corrxy2 = ($sumx2 - ($sumx**2/$n))*($sumy2 - ($sumy**2/$n)); $corrxy = $corrxy1/($corrxy2**(1/2)); $corrxy = sprintf("%.2f",$corrxy); return $corrxy; }