#!/usr/bin/perl –Tw use strict; use CGI ':standard'; use Template; my $t = Template->new; my $cut = param(‘cut’); # submit button’s name attribute = cut my $cut = substr($cut, -1, 1); # redefine ‘cut’ to be only 2nd-to-last letter of submission # does this substr overwrite the param definition of $cut? my $range = 5; # define number of lines (for random_line function) as a # random integer between 1 and 5 my $minimum = 1; # with an offset so range starts at 1 and not 0 my $nr_of_lines = int(rand($range)) + $minimum; # analyze $cut value, open appropriate infinity file and # call random number of lines if (my $cut =~ /[a-e]/i) { # does $cut need “my”? if yes, inside or outside parens? open (INFINITY01, "infinity01.txt") or die "file is temporarily unavailable: $!\n"; # need another nested set of curly brackets for print func? # or is print irrelevant; ie, should the template be called # here? where does the flow control language belong – here, # or in template? and how should it be phrased? print random_line($INFINITY01 [, $nr_of_lines]); # is $INFINITY01 the correct way to reference the file here? # should it be $infinity01? infinity01.txt? # why is $nr_of_lines in brackets, and what function does # the comma serve? I found this function at cpan, but # haven’t been able to find much else about it online. # does “my” need to be added to $nr_of_lines? if yes, inside # brackets or out? close INFINITY01; } elsif (my $cut =~ /[f-j]/i) { open (INFINITY02, "infinity02.txt") or die "file is temporarily unavailable: $!\n"; print random_line($INFINITY02 [, $nr_of_lines]); close INFINITY02; } elsif ($cut =~ /[k-o]/i) { open (INFINITY03, "infinity03.txt") or die "file is temporarily unavailable: $!\n"; print random_line($INFINITY03 [, $nr_of_lines]); close INFINITY03; } elsif ($cut =~ /[p-t]/i) { open (INFINITY04, "infinity04.txt") or die "file is temporarily unavailable: $!\n"; print random_line($INFINITY04 [, $nr_of_lines]); close INFINITY04; } elsif ($cut =~ /[u-z/i) { open (INFINITY05, "infinity05.txt") or die "file is temporarily unavailable: $!\n"; print random_line($INFINITY05 [, $nr_of_lines]); close INFINITY05; # include fail-safe statement in case $cut doesn’t match any # letter of the alphabet } else { print "Yes, no, maybe so.\n"; } }