#!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'); $v06= $query->param('v06'); $v07= $query->param('v07'); $v08= $query->param('v08'); $v09= $query->param('v09'); $v10= $query->param('v10'); $v11= $query->param('v11'); $v12= $query->param('v12'); $v13= $query->param('v13'); $pass= $query->param('pass'); if($pass < 1) { $pass = 0; } ($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"; print $query->header; print $query->start_html(-title=>'Homework 5'); print ""; if ($pass == 1) { $pmean = &subjectmean($v01, $v02, $v03, $v04, $v05, $v06, $v07, $v08, $v09, $v10, $v11, $v12, $v13); open(INFO, ">>$ENV{'DOCUMENT_ROOT_OLD'}/www/heplerlabs.com/P593/homework_5.txt"); print INFO "$date1,$date2,$v01,$v02,$v03,$v04,$v05,$v06,$v07,$v08,$v09,$v10,$v11,$v12,$v13,$pmean,endline\n"; close(INFO); &results('homework_5.txt',15); print "Thanks for participating!

"; print "Your score on the Attitudes toward Dualism scale is $pmean

"; print "Thus far, the sample average is $mean and the standard deviation is $sd.

"; print "Return to Hepler Labs\n"; } if ($pass == 0) { print "
"; print "
Attitudes toward Dualism



"; &Questionnaire(); print ""; print ""; &passhidden(); print "
"; } print $query->end_html; #This subroutine automates questionnaire generation sub Questionnaire { #Stores questionnaire items @items = ( "The mind is equivalent to the brain", "The mind is a non-physical property", "It is impossible for science to ever have a complete understanding of the mind", "My thoughts, personality, preferences, and choices are all just a product of my brain functions", "Whether one is a good or bad person can be completely altered by changes in the brain", "In the future, it may be possible to know exactly what another person is thinking by looking at their brain activity", "People have a non-physical soul (or spirit) that animates the physical body", "I believe the brain and soul are the same thing", "I believe the mind and soul are the same thing", "Free will is an illusion produced by the brain", "The mind interacts with the brain, but is separate from brain", "In the future, it may be possible to know someone's personality by looking at their brain activity", "The true self is not governed by the brain, but by a person's soul" ); #Prints each questionnaire item separately with radio buttons from 1 - 5 $item = 0; @variables = ("v01","v02","v03","v04","v05","v06","v07","v08","v09","v10","v11","v12","v13"); foreach $variable (@items) { print "$item. $variable
"; print "Strongly Disagree"; print ""; print ""; print ""; print ""; print ""; print "Strongly Agree

"; ++$item; } } #This subroutine calculates the mean and standard deviation for a variable in the data set sub results { #The first input indicates the file name to be opened #The second input indicates which column in the data matrix will be used to find the sample average and standard deviation $filename = $_[0]; $index = $_[1]; $fullfilename = "$ENV{'DOCUMENT_ROOT_OLD'}/www/heplerlabs.com/P593/" . $filename; open(INFO, $fullfilename); @data = ; close(INFO); #N is the number of non-zero entries in the column being averaged (i.e. the number of participants who actually responded to this questionnaire) #sum is the sum of entries in the column being averaged #ssdiff is the sum of squared differences between each entry in the column and the column average (i.e. ssdiff = SIGMA(xi - xbar)^2) $N = 0; $sum = 0; $ssdiff = 0; #Finds the cumulative sum and total N for the variable foreach $row (@data) { @a = split(/,/,$row); if($a[$index] > 0) { $N = ++$N; $sum = $sum + $a[$index]; } } #Calculates the mean of the variable if ($N > 0) { $mean = sprintf("%.2f",$sum/$N); } else { $mean = "The sample average cannot be computed because there are too few cases"; } #Calculates the standard deviation of the variable foreach $row (@data) { @b = split(/,/,$row); if($b[$index] > 0) { $ssdiff = $ssdiff + (($b[$index] - $mean)*($b[$index] - $mean)); } } if ($N > 0) { $sd = sprintf("%.2f",sqrt((1/($N - 1))*$ssdiff)); } else { $sd = "The sample standard deviation cannot be computed because there are too few cases"; } #Returns the mean and standard deviation for the variable return $mean; return $sd; } #Calculates subject's mean for the questionnaire sub subjectmean { #Stores the array length in N and initializes other variables for later use $N = @_; $validN = 0; $sum = 0; $mean = 0; for($i = 0; $i <= ($N-1); ++$i) { if($_[$i] > 0) { $sum = $sum + $_[$i]; ++$validN; } } if($validN > 0) { $mean = sprintf("%.2f",$sum/$validN); } return $mean; } #Passes variables that the user has entered sub passhidden { print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; }