#!C:/perl/bin/perl.exe use CGI::Carp qw(fatalsToBrowser); use CGI; $query = new CGI; # Flip a coin $pass= $query->param('pass'); $v1= $query->param('v1'); $v2= $query->param('v2'); $v3= $query->param('v3'); $v4= $query->param('v4'); print $query->header; print $query->start_html(-title=>'randomization'); print ""; print "This script uses a subroutine to flip a coin. The outcome can be used to assign people to conditions.

"; for ($x=0;$x<20;$x++) { $coin = &coinToss(); print "$coin
"; } print $query->end_html; # ----------------- Subroutines ----------------------------- # for a good tutorial/overview of Perl subroutines, see # http://www.comp.leeds.ac.uk/Perl/subroutines.html #------------------------------------------------------------ sub coinToss { # this subroutine randomizes the elements of an array and returns the new array srand; my($side) = "heads"; my($coin) = rand(); if($coin < .50){$side = "tails";} return $side; }