Did you know...
#!/usr/bin/perl # "Did you know?" -- Dennis Brown -- 01/16/98 # # Opens a data file and reads in description, URL pairs. Prints out # a randomly chosen pair in HTML. To be used as an SSI script. # # The data file has a loose format as follows. The description # goes on ONE line and the URL goes on ONE line which follows its # description. If you need more than 80 chars that's OK but it all has to # be on one line. You can have blank lines in the file and you can have # comments by making the first character of the comment line a #. # Location of the data file. $DATAFILE = "/home/dgbrown/public_html/gamesmuseum/musbin/diduno.txt"; # Target frame for the URLs. $TARGET = "main"; # String for the link on the HTML page. $LINKSTR = "Click here!"; # Print out MIME header. print "Content-type: text/html\n\n"; # Open the data file. open(DIDUNO, $DATAFILE) or die "Can't open $DATAFILE\n"; # Global variables $numentries = 0; # Number of entries found $gotdesc = 0; # Found a description? $goturl = 0; # Found a URL? # Read in lines of the file. LINE: while ($line = ) { # Skip comment line. if ($line =~ /^#/) { next LINE; } # Skip blank line. if ($line =~ /^\s+/) { next LINE; } # Remove trailing newline. chomp($line); # If we have neither a description or a URL, assume this line # is a description. if ((!$gotdesc) && (!$goturl)) { $desc[$numentries] = $line; $gotdesc = 1; next LINE; } # If we have a description but no URL, assume this line is a URL. if (($gotdesc) && (!$goturl)) { $url[$numentries] = $line; $goturl = 1; $numentries++; next LINE; } # If we have both a desc and URL, assume line is a desc for next entry. if (($gotdesc) && ($goturl)) { $desc[$numentries] = $line; $gotdesc = 1; $goturl = 0; next LINE; } } # Randomly choose one entry. srand; $whichone = int(rand($numentries)); # Print out the desc and URL in HTML. print "$desc[$whichone]\n"; print "

$LINKSTR\n"; # Close file. close(DIDUNO); exit;