#!C:/perl/bin/perl.exe use CGI::Carp qw(fatalsToBrowser); use CGI; $query = new CGI; # Randomize items in a questionnaire # and present different questionnaires on different pages $pass= $query->param('pass'); $r0= $query->param('r0'); $r1= $query->param('r1'); $r2= $query->param('r2'); $r3= $query->param('r3'); $r4= $query->param('r4'); @itemIndex= $query->param('itemIndex'); # Information about the questionnaire $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."; @variableNames = (r0,r1,r2,r3,r4); @items = ($v0,$v1,$v2,$v3,$v4); if($pass < 1){ $pass = 0; } print $query->header; print $query->start_html(-title=>'randomization'); print ""; if($pass == 6){ print "Thank you for your responses.
"; print "itemIndex = @itemIndex

"; 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 >= 1 && $pass <= 5){ # randomly select a condition # $i will be used as an index value to determine which item to present $i = $pass - 1; print "
"; print "itemIndex = @itemIndex
"; print "this itemIndex = $itemIndex[$i]


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

"; &printLikert5($variableNames[$itemIndex[$i]]); print $query->hidden(itemIndex, @itemIndex); print ""; $pass = $pass + 1; print ""; print $query->hidden(r0, $r0); print $query->hidden(r1, $r1); print $query->hidden(r2, $r2); print $query->hidden(r3, $r3); print $query->hidden(r4, $r4); print "
"; } if($pass == 0){ print "
"; @itemIndex = &randomize(0,1,2,3,4); print "Informed consent goes here.

(The item order is also being randomized in this page: @itemIndex.)

"; # Remember that arrays have to be passed forward as hidden tags # through the use of CGI.pm. We can't do this via simple HTML passed # through Perl. print $query->hidden(itemIndex, @itemIndex); 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"; }