#!/usr/bin/perl use CGI qw(:standard); @quotes = ( "snowball.txt", "quote2.txt", "quote1.txt", "quote4.txt", "nemo.txt", "quote6.txt", "surfsUp.txt", "quote8.txt", "quote9.txt", "croce.txt", "croce2.txt", "bball.txt" ); $n = @quotes; $quoteList = param('quoteNumbers'); $quoteList =~ tr/ //d; if ($quoteList eq "") { $quoteList = rand(@quotes) + 1; } # param('quoteNumbers', "$quoteList"); @quoteList = split /,/, $quoteList; print "Content-type: text/html\n\n"; print "\n\n\n"; print start_form, "\n", "Enter a comma/hyphen separated list - legal values are 1 through $n", ". \n
\nLeave textbox blank to get a random quote selected.", "\n", "
Typing 1-$n means all the quotes will be displayed.", "
Typing 1,3-5,9 would be the same as typing 1,3,4,5,9 mixing" . " commas and hyphens. \n", p, textfield('quoteNumbers'), p, "\n", submit('See the quotes'), "\n", end_form, "\n\n"; $n = @quoteList; for ($i = 1; $i <= $n; $i++) # expand the hyphenated lists 1-4 { # to 1,2,3,4 for example $front = shift( @quoteList ); @range = split /-/, $front; if (@range > 1) { $stopNumber = $range[1]; for ($j = $range[0]; $j <= $stopNumber; $j++) { push(@quoteList, $j); } } else { push(@quoteList, $front); } } foreach (@quoteList) { print "\n", p, "
", p, "\n"; $fileName = $quotes[$_ - 1]; open(FILE, $fileName); while () { print $_; } close FILE; } print "\n"; print "\n";