#!C:/perl/bin/perl.exe use CGI::Carp qw(fatalsToBrowser); use CGI; $query = new CGI; # Randomize items in a questionnaire $pass= $query->param('pass'); $r0= $query->param('r0'); $r1= $query->param('r1'); $r2= $query->param('r2'); $r3= $query->param('r3'); $r4= $query->param('r4'); if($pass < 1){ $pass = 0; } print $query->header; print $query->start_html(-title=>'randomization'); print ""; if($pass == 1){ print "Thank you for your responses.
"; print "item 0 = $r0
"; print "item 1 = $r1
"; print "item 2 = $r2
"; print "item 3 = $r3
"; print "item 4 = $r4
"; # save data if desired } if($pass == 0){ # randomly select a condition print "
"; $v0 = "I drink coffee daily."; $v1 = "I love coffee."; $v2 = "It is coffee time now."; $v3 = "I have java for brains."; $v4 = "Sleep? You can sleep when you're dead."; @itemIndex = &randomize(0,1,2,3,4); @variableNames = (r0,r1,r2,r3,r4); @items = ($v0,$v1,$v2,$v3,$v4); for ($i=0;$i<=4;$i++) { print "$items[$itemIndex[$i]]

"; &printLikert5($variableNames[$itemIndex[$i]]); } print ""; print ""; print "
"; } print $query->end_html; # ----------------- Subroutines ----------------------------- # for a good tutorial/overview of Perl subroutines, see # http://www.comp.leeds.ac.uk/Perl/subroutines.html #------------------------------------------------------------ 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; } sub printLikert5 { # Subroutine by Jenn Smith print " Strongly Disagree
\n Disagree
\n Neutral
\n Agree
\n Strongly Agree


\n\n"; }