#!C:/perl/bin/perl.exe use CGI::Carp qw(fatalsToBrowser); use CGI; $query = new CGI; # Read in the variables $pass= $query->param('pass'); $thisCondition=$query->param('thisCondition'); $luckyNumber= $query->param('luckyNumber'); $luckyNumber2= $query->param('luckyNumber2'); $question= $query->param('question'); $color= $query->param('color'); $yourResponse=$query->param('yourResponse'); $v0=$query->param('v0'); $v1=$query->param('v1'); $v2=$query->param('v2'); @itemIndex= $query->param('itemIndex'); # 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"; # Remove commas from free responses $question =~ s/\n/
/g; $question =~ s/\r/ /g; $question =~ s/\,/ /g; # Set pass = 0 if($pass < 1){ $pass = 0; } # Define the 9 possible reponses $r1 = "It is decidedly so"; $r2 = "Signs point to yes"; $r3 = "You may rely on it"; $r4 = "Without a doubt"; $r5 = "Reply hazy - try again"; $r6 = "Concentrate and ask again"; $r7 = "Better not tell you now"; $r8 = "Don't count on it"; $r9 = "My sources say no"; # Define the 3 questions $q0 = "What is your astrological sign?


"; $q1 = "Do you think Magic 9 Balls are accurate?

Not at all accurate Very accurate

"; $q2 = "What is your favorite color?


"; @items = ($q0,$q1,$q2); print $query->header; print $query->start_html(-title=>'Magic 9 Ball'); #--------------------- # pass = 6 #--------------------- if($pass == 6){ print "
"; @responses = &randomize($r1,$r2,$r3,$r4,$r5,$r6,$r7,$r8,$r9); $yourResponse = $responses[$luckyNumber2]; # save the data to a text file open(INFO, ">>$ENV{'DOCUMENT_ROOT_OLD'}/www/relationshipsresearch.com/P593/HW6.txt"); print INFO "$date1,$date2,$luckyNumber,$question,$yourResponse,$color,"; print INFO "$v0,$v1,$v2,"; print INFO "endline\n"; close (INFO); # Participant Feedback print ""; print ""; print ""; print ""; print ""; print ""; print "
"; print ""; print ""; print "
The Magic 9 Ball Says...
"; print "
"; print ""; print "
'$yourResponse' 
"; print ""; print "(Your question was: $question)








"; print "Ask another question

"; print ""; print "This page was created by Practical Magic Inc. © 2010

"; print ""; print "
"; } # end pass = 6 #--------------------- # pass = 5 #--------------------- if($pass == 5){ print ""; print ""; print ""; print ""; print ""; print ""; print ""; print "
"; print ""; print ""; print "
Ask your question!

"; print ""; print "In the space below, please type your question for the Magic 9 Ball.


"; print "

"; print ""; print "
"; print ""; &passHidden(); print "
"; } # end pass = 5 #--------------------- # pass = 4 #--------------------- if($pass == 4){ print "
"; $luckyNumber = &randomSelect(1,2,3,4,5,6,7,8,9); $luckyNumber2 = $luckyNumber - 1; print ""; print ""; print ""; print ""; print ""; print ""; print "
"; print ""; print ""; print "
The Magic 9 Ball

"; print "
"; print "
$date1

"; print "Today, your lucky, single digit number is $luckyNumber.

"; print ""; print "
"; print ""; &passHidden(); print "
"; } # end pass = 4 #------------------ # pass = 1,2,3 #------------------ if($pass >= 1 && $pass <= 3){ # $i will be used as an index value to determine which item to present $i = $pass - 1; print "
"; print ""; print ""; print ""; print ""; print ""; print ""; print "
"; print ""; print ""; print "
The Magic 9 Ball

"; print "
"; print ""; print "$items[$itemIndex[$i]]

"; print ""; print "
"; $pass = $pass + 1; print ""; &passHidden(); print "
"; } # End pass = 1,2,3 #------------------ # pass = 0 #------------------ if($pass == 0){ # Create item index @itemIndex = &randomize(0,1,2); # Define the conditions $cond0= "Witches and mystics regularly use Magic 9 Balls to predict the future. Although there are skeptics about its utility, researchers have found that the Magic 9 Ball predicts future events better than chance."; $cond1= "Witches and mystics regularly use Magic 9 Balls to predict the future. Many people are skeptical of this practice because researchers have found that the Magic 9 Ball does not predict future events better than chance."; # randomly select a condition $thisCondition = &randomSelect(0,1); $color = &randomSelect('#990099','#3333CC','#009933','#CC0000','#FF9933','#660099'); print "
"; print ""; print ""; print ""; print ""; print ""; print ""; print "
"; print ""; print ""; print "
The Magic 9 Ball

"; print "
"; print ""; #present stimuli depending on condition if($thisCondition == 0){ print "$cond0

"; } else{ print "$cond1

"; } print ""; print "
"; print ""; &passHidden(); print "
"; } # end pass = 0 # ----------------- Subroutines ----------------------------- # for a good tutorial/overview of Perl subroutines, see # http://www.comp.leeds.ac.uk/Perl/subroutines.html #------------------------------------------------------------ #----------------------- # randomSelect Subroutine #----------------------- sub randomSelect { # this subroutine randomizes the elements of an array and returns the 0th value of the new array srand; my(@new) = (); while (@_){ push(@new, splice(@_, rand @_,1)); } return $new[0]; } #----------------------- # rondomize Subroutine #----------------------- sub randomize { # this subroutine randomizes the elements of an array and returns the new array srand; my(@new) = (); while (@_){ push(@new, splice(@_, rand @_,1)); } return @new; } #----------------------- # passHidden Subroutine #----------------------- sub passHidden { print $query->hidden(itemIndex, @itemIndex); print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; } print $query->end_html;