#!C:/perl/bin/perl.exe use CGI::Carp qw(fatalsToBrowser); use CGI; $query = new CGI; $v01= $query->param('v01'); $v02= $query->param('v02'); $v03= $query->param('v03'); $v04= $query->param('v04'); $v05= $query->param('v05'); ($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"; # Create a composite score (average the responses to all the items) $esteem = ($v01 + $v02 + $v03 + $v04 + $v05)/5; # Round the score to 2 decimal places and assign it a new variable name $esteem2 = sprintf("%.2f",$esteem); open(INFO, ">>$ENV{'DOCUMENT_ROOT'}/P593/form3.txt"); print INFO "$date1,$date2,$v01,$v02,$v03,$v04,$v05,$esteem2,endline\n"; close (INFO); print $query->header; print $query->start_html(-title=>'Thank You'); # Substitution. What is printed to the browser is not $esteem2 literally, but the value of this variable. print "Thank you. Your self-esteem score is $esteem2 on a scale ranging from 1 (low) to 5 (high). (Note to students: No reverse coding is used in this demo so the scores are not accurate.)"; print $query->end_html;