#!/usr/bin/perl ############################################################################## # # # StareForm.cgi # # Copyright (C) 2003 by Charles Overby # # # # Written: 11 January 2003 # # # # Purpose: Read the input from the user data form and build an experiment. # # Return the experiment to the user for execution. # # # ############################################################################## # ############################################################################## # # Get the data sent by the form. Translate control characters, and load # an array with the Name and Value pairs. # ############################################################################## # read(STDIN, $input, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $input); foreach $pair (@pairs) { # seperate the name and value pairs ($name, $value) = split(/=/, $pair); # translate plus (+) into a space $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # translate plus (+) into a space $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # remove any comment lines $value =~ s///g; # trim leading and trailing whitespace $value =~ s/^\s*(.*)\s*$/$1/; # validate the data sent by the form, error on missing data if ($value eq "") { &fatal_error("Vital data is missing!"); } # If it is valid, save it into the FORM hash $FORM{$name} = $value; } ############################################################################## # # Produce an experiment of 20 trials of randomly selected Stare/No Stare # commands to be formatted into HTML for submission to the user. # ############################################################################## # @trials = qw(Trial1 Trial2 Trial3 Trial4 Trial5 Trial6 Trial7 Trial8 Trial9 Trial10 Trial11 Trial12 Trial13 Trial14 Trial15 Trial16 Trial17 Trial18 Trial19 Trial20); foreach $trial (@trials) { $iRandInt = (int(rand 100)); if (($iRandInt < 10) || ((20 <= $iRandInt) && ($iRandInt < 30)) || ((40 <= $iRandInt) && ($iRandInt < 50)) || ((60 <= $iRandInt) && ($iRandInt < 70)) || ((80 <= $iRandInt) && ($iRandInt < 90))) { @experiment{$trial} = "Stare"; } else { @experiment{$trial} = "No Stare"; } } ############################################################################## # # Write the header data out to the return HTML page. # ############################################################################## # print "Content-type: text/html\n\n"; print "