#!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'); $s0= $query->param('s0'); $s1= $query->param('s1'); $s2= $query->param('s2'); $s3= $query->param('s3'); $s4= $query->param('s4'); @questIndex= $query->param('questIndex'); # Information about the questionnaires $rr0 = "I drink coffee daily."; $rr1 = "I love coffee."; $rr2 = "It is coffee time now."; $rr3 = "I have java for brains."; $rr4 = "Sleep? You can sleep when you're dead."; $ss0= "I feel that I'm a person of worth, at least on an equal plane with others."; $ss1= "I feel that I have a number of good qualities."; $ss2= "All in all, I am inclined to feel that I am a failure."; $ss3= "I am able to do things as well as most other people."; $ss4= "I feel I do not have much to be proud of."; @rvariableNames = (r0,r1,r2,r3,r4); @svariableNames = (s0,s1,s2,s3,s4); @rritems = ($rr0,$rr1,$rr2,$rr3,$rr4); @ssitems = ($ss0,$ss1,$ss2,$ss3,$ss4); if($pass < 1){ $pass = 0; } print $query->header; print $query->start_html(-title=>'randomization'); print ""; if($pass == 3){ print "Thank you for your responses.
"; print "

coffee questions
"; print "item 0 = $r0
"; print "item 1 = $r1
"; print "item 2 = $r2
"; print "item 3 = $r3
"; print "item 4 = $r4
"; print "

self-esteem questions
"; print "item 0 = $s0
"; print "item 1 = $s1
"; print "item 2 = $s2
"; print "item 3 = $s3
"; print "item 4 = $s4
"; # save data if desired } if($pass >= 1 && $pass <=2 ){ # $i will be used as an index value to determine which item to present $z = $pass - 1; print "
"; print "questIndex = @questIndex
"; print "this questIndex = $questIndex[$z]


"; if($questIndex[$z]==0){ @itemIndex = &randomize(0,1,2,3,4); for ($i=0;$i<=4;$i++) { print "$rritems[$itemIndex[$i]]

"; &printLikert5($rvariableNames[$itemIndex[$i]]); } } if($questIndex[$z]==1){ @itemIndex = &randomize(0,1,2,3,4); for ($i=0;$i<=4;$i++) { print "$ssitems[$itemIndex[$i]]

"; &printLikert5($svariableNames[$itemIndex[$i]]); } } print $query->hidden(questIndex, @questIndex); $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 $query->hidden(s0, $s0); print $query->hidden(s1, $s1); print $query->hidden(s2, $s2); print $query->hidden(s3, $s3); print $query->hidden(s4, $s4); print ""; print "
"; } if($pass == 0){ print "
"; @questIndex = &randomize(0,1); print "Informed consent goes here.

(The quest order is also being randomized in this page: @questIndex.)

"; print $query->hidden(questIndex, @questIndex); 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"; }