#!/home/davidtg/local/FreeBSD/4/bin/perl -- # -*- Perl -*- # just a quickie to get it in here # $Id: random.pl,v 1.9 2002/08/15 10:45:04 davidtg Exp $ # # File: random.cgi Date: Mar 20, 1995 # Author: Marcus E. Hennecke # # CGI script to randomly display a joke from my light bulb joke # collection. This script also does some logging to figure out where # people came from. For users of Netscape 1.1 or later, the script # sets the Refresh header so that it automatically reloads joke after # joke after joke... # Here is a portion of the underlying light bulb joke database (think # away the # characters): # #
How many Alaskan women does it take to change a light bulb? #
"Hey Bob, this is Carol ... I think I have a light bulb out over here." # # #
How many Alaskan men does it take to change a light bulb? #
Oh, none ... they just have one of their girlfriends do it. [bitter # laugh] # Each joke consists of keywords and the actual joke. Jokes can span # several lines and are separated by empty lines. use CGI; my $cgi = new CGI; my $docroot = $ENV{'DOCUMENT_ROOT'}; ### First, let's do some defining. $LBJFile = $docroot . "/lbbase.html"; # access the file $LBNO = 742; # Number of jokes in the file ### should be calculated, not hardcoded ### Now here is where the joke is selected. srand; # Seed the random number generator $jokeno = rand($LBNO+1); # Randomly pick one joke $/ = "\n\n"; # Jokes are separated by empty lines open(LB,$LBJFile); # Open the joke database while ( $jokeno-- > 0) { # Count down the jokes... $joke = ; ###$_ = ; # ... as you load them }; s///g; # Remove the keywords ### And finally, the joke is sent to standard output. # The trick is in the Refresh: header. It tells the browser after how # many seconds it is supposed to reload the document. $seconds = int ( 5 + length($joke) / 32 ); # Compute appropriate display time print ($cgi->header(-type=>'text/html')); print " Random Light Bulb Joke

Random Light Bulb Joke

$joke

In case you are using Netscape 1.1 or later:
I'll display this joke for $seconds seconds and then load another.
To stop display, hit the `Back' button or select a link.

The source code is available as well.
I have a whole collection of light bulb jokes. You should check it out!


David T-G bulbs\@justpickon.org
\n";