#! /usr/bin/perl

use strict "vars";
use CGI;
#------------------------------------------------------------------------------
my $HTMLDirectory = "/home/geoff/public_html";
my $CoolURLsFile = "../CoolURLs";
#------------------------------------------------------------------------------
    my $CoolURLsHandle = "CoolURLsHandle";
    my $InputLine;
    my @CoolURLs;
    my $URLToRedirectTo;
    my $WWWPage;
    
    open($CoolURLsHandle,"<$CoolURLsFile") || 
    die("ERROR: Cannot open $CoolURLsFile for reading\n");
    while (defined($InputLine = <$CoolURLsHandle>)) {
        chomp($InputLine);
        push(@CoolURLs,($InputLine));
    }
    close($CoolURLsHandle);
#DEBUG print("URLs are @CoolURLs\n");

    $URLToRedirectTo = RandomSelect(@CoolURLs);

#----Make the redirect WWW page
    $WWWPage = new CGI;
    print($WWWPage->redirect($URLToRedirectTo));
    print($WWWPage->header);
#----Here's anotherway, in the header
# <META HTTP-EQUIV="REFRESH" CONTENT="0; URL=$URLToRedirectTo">

#----And in case that doesn't work
    print($WWWPage->start_html(-title=>'Going to a Cool WWW Page'));
    print("Automatically going to <A HREF=\"$URLToRedirectTo\">A Cool WWW Page</A>.\n");
    print($WWWPage->end_html);
#------------------------------------------------------------------------------
sub RandomSelect {
my @CoolURLs = @_;

my $RandomIndex;

$RandomIndex = int(rand(@CoolURLs));
#DEBUG print("Random number is $RandomIndex\n");

return($CoolURLs[$RandomIndex]);
}
#------------------------------------------------------------------------------
