#!C:/perl/bin/perl.exe use CGI::Carp qw(fatalsToBrowser); use CGI; $query = new CGI; # Randomly select one item from a list of items $pass= $query->param('pass'); $v1= $query->param('v1'); $v2= $query->param('v2'); $v3= $query->param('v3'); $v4= $query->param('v4'); if($pass < 1){ $pass = 0; } print $query->header; print $query->start_html(-title=>'randomization'); print ""; if($pass == 1){ $thisCondition = &randomSelect($v1,$v2,$v3,$v4); print "The original set of of items was $v1,$v2,$v3,$v4.
"; print "This randomly selected item is $thisCondition.
"; } if($pass == 0){ print "
"; print "Type 4 numbers click the button to see one selected at random.
"; print "
"; print "
"; print "
"; print "
"; 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 randomSelect { # this subroutine randomizes the elements of an array and returns the new array srand; my(@new) = (); while (@_){ push(@new, splice(@_, rand @_,1)); } return $new[0]; }