1 #!/usr/bin/perl
 2 # Note: I detest, absolutely _hate_ safeperl.  I mean, what?  I can't even
 3 # use these two:
 4 #use warnings;
 5 #use strict;
 6 #
 7 # You can see the results of this script here:
 8 # http://users.ox.ac.uk/cgi-bin/safeperl/worc2070/fortune.cgi
 9 # You can grab the fortune file from:
10 # http://users.ox.ac.uk/~worc2070/fortune/firefly-quotes
11 
12 print "Content-type: text/plain\n\n" if $ENV{HTTP_HOST};
13 my $file;
14 if ( defined( $ENV{HTTP_HOST} ) ) {
15 	$file = "../public_html/fortune/firefly-quotes";
16 } else {
17 	$file = "/u3/d/worc2070/public_html/fortune/firefly-quotes";
18 }
19 
20 
21 open(F, $file) || print "Ack: couldn't open fortune file '$file' - don't expect the rest to work!";
22 
23 srand(time);
24 
25 my $number = 0;
26 my @fortune;
27 
28 while ( <F>) {
29 	chomp;
30 	next if m/^$/;
31 	if ( m/^%$/ ) {
32 		$number++ if $fortune[$number];
33 	} else {
34 		$fortune[$number] .= $_ . "\n";
35 	}
36 }
37 
38 my $thisfortune = $fortune[ (rand(1000)*time)%($number + 1) ];
39 print "$thisfortune";
40 # http://users.ox.ac.uk/cgi-bin/safeperl/worc2070/fortune.cgi
41 


syntax highlighted by Code2HTML, v. 0.9.1