#!C:/perl/bin/perl.exe use CGI::Carp qw(fatalsToBrowser); use CGI; $query = new CGI; #--------------------------- $trials= 4; $previoussec= $query->param('trialsec'); $previousmin= $query->param('trialmin'); $previoushour= $query->param('trialhour'); $pass= $query->param('pass'); $rt00= $query->param('rt00'); $rt01= $query->param('rt01'); $rt02= $query->param('rt02'); $rt03= $query->param('rt03'); $trialnumber= $query->param('trialnumber'); @trialorder= $query->param('trialorder'); #--------------------------- if($pass < 1){$pass=0;} #--------------------------- print $query->header; print $query->start_html(-title=>'Trials'); # If consent presented, pass is 1. Present trials if($pass >= 1){ @varnum = ("00","01","02","03"); @stimuli= ("happy", "lonely", "secure", "anxious"); # Retrieve time the data were submitted ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); #--------------------------- # Do the following if this is not the first trial if($trialnumber != 0){ $currenthour = $hour; $currentmin = $min; $currentsec = $sec; $rt= 0; $trialindex= $trialorder[$trialnumber]; # subtract seconds if($previoussec > $currentsec){ $secdiff = ((60 + $currentsec) - $previoussec); $currentmin = $currentmin - 1; } if($previoussec <= $currentsec){ $secdiff = $currentsec - $previoussec; } # subtract minutes if($previousmin > $currentmin){ $mindiff = ((60 + $currentmin) - $previousmin); $currenthour = $currenthour - 1; } if($previousmin <= $currentmin){ $mindiff = $currentmin - $previousmin; } # subtract hours if($previoushour > $currenthour){ $hourdiff = ((24 + $currenthour) - $previoushour); } if($previoushour <= $hour){ $hourdiff = $currenthour - $previoushour; } # convert difference to seconds $rt = (3600*$hourdiff)+(60*$mindiff)+($secdiff); $temp = "rt" . $trialorder[($trialnumber - 1)]; $$temp = $rt; } else{ # For the first trial $trialnumber = 0; $trialindex= $trialorder[$trialnumber]; } print ""; # Print RT feedback for previous trial if 2nd trial or higher if($trialnumber >= 1){ print "Time to recall on previous trial (seconds): $rt.

"; } # If still have trials to go, present the next trial if($trialnumber < $trials ){ print "
"; # Select stimulus for this trial $stimulus= $stimuli[$trialindex]; print "
Recall a time when you felt:

"; print "$stimulus

"; print "Press the button when you have a specific experience in mind.

"; print "
"; $count= $trialnumber + 1; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print $query->hidden('trialorder', @trialorder); print "
"; } # If no more trials left, save data and debrief else{ # Save data open(INFO, ">>$ENV{'DOCUMENT_ROOT'}/P593/rtdemo.txt"); print INFO "$mon/$mday/$year,$hour:$min:$sec, $ip, "; print INFO "$rt00,$rt01,$rt02,$rt03\n"; close (INFO); # Open data file for analysis open(INFO, "$ENV{'DOCUMENT_ROOT'}/P593/rtdemo.txt"); @data = ; close (INFO); print "Thank you. You have finished all trials.
"; print "Here are your response times:

"; print "$stimuli[0] : $rt00 seconds
"; print "$stimuli[1] : $rt01 seconds
"; print "$stimuli[2] : $rt02 seconds
"; print "$stimuli[3] : $rt03 seconds
"; $mypos = ($rt00 + $rt02)/2; $myneg = ($rt01 + $rt03)/2; print "
It took you $mypos seconds, on average, to recall positive memories and $myneg seconds to recall negative ones.

"; # Find sample averages for pos and neg trials $sumpos = 0; $sumneg = 0; $n = 0; foreach $key (@data) { ($date,$time,$ip, $p01, $n01, $p02, $n02)=split(/,/,$key); $sumpos = $sumpos + (($p01 + $p02)/2); $sumneg = $sumneg + (($n01 + $n02)/2); $n = $n + 1; } $meanpos = sprintf("%.4f", ($sumpos/$n)); $meanneg = sprintf("%.4f", ($sumneg/$n)); print "On average, people in this sample (N = $n) have taken $meanpos seconds to recall positive memories and $meanneg to recall negative memories.
"; } } # end pass >= 1 # Present Consent Information if($pass == 0){ # Randomize the order of trials @trialorder = ("00", "01", "02", "03"); srand; @new = (); while (@trialorder){ push(@new, splice(@trialorder, rand @trialorder,1)); } @trialorder= @new; # Present the overview/consent print ""; print "
"; print "In this demonstration, you will be asked to recall different kinds of emotional experiences from your past. As soon as you're able to recall an experience that is characterized by the emotion printed in bold, click the button. The web page will then take you to the next recall trial. Please try to recall these experiences as quickly as possible.

"; # Pass the randomized trail order forward in a hidden tag print $query->hidden('trialorder',@trialorder); print ""; print ""; print "

For testing purposes: trialorder = @trialorder

"; print "
"; } # end pass == 0 print $query->end_html;