CGI Random Text
CGI
Download (.zip)
#!perl
$random_file = "random.txt";
$delimiter = "\n";
open(FILE,"$random_file") || &error('open->random_file',$random_file); @FILE = <FILE>; close(FILE);
$phrases = join('',@FILE);
@phrases = split(/$delimiter/,$phrases);
srand(time ^ $$);
$phrase = rand(@phrases);
print "Content-type: text/html\n\n";
print $phrases[$phrase];
exit;
sub error { ($error,$file) = @_; print <<"END_ERROR"; Content-type: text/html
<html> <head> <title>ERROR: Random File Unopenable</title> </head> <body bgcolor=#FFFFFF text=#000000> <center> <h1>ERROR: Random File Unopenable</h1> </center>
The random file, as specified in the \$random_file perl variable was unopenable.<p> END_ERROR
if (-e $random_file) { print "The file was found on your system, so make sure that it is\n"; print "readable by the web server. This means you will need to\n"; print "execute the following command:<pre>\n"; print " chmod 744 $random_file\n"; print "</pre>\n"; } else { print "The file was not found on your file system. This means that\n"; print "it has either not been created or the path you have specified\n"; print "in \$trrandom_file is incorrect.\n"; } exit; }
|