#!/usr/local/bin/perl # *********************************************************************** # # * * # # * Copyright (c) 1996-1999 Scott Crevier * # # * All Rights Reserved Worldwide * # # * * # # * This program product material is the property of Scott Crevier. * # # * This program may be used and modified by anyone free of charge, * # # * as long as this copyright notice remains in tact. By using this * # # * code, you agree to indemnify Scott Crevier from any liability * # # * that might arise from its use. * # # * * # # * scott@crevier.org - Scott M. Crevier - www.crevier.org * # # *********************************************************************** # # * smcRandom v2.1 15-Jul-2001 * # # * * # # * This script returns a random line from the file whose name is * # # * passed in the QUERY_STRING. * # # * * # # * Suggested usage: * # # * * # # * * # # * * # # *********************************************************************** # # *********************************************************************** # # * Get the filename from $QUERY_STRING. * # # *********************************************************************** # if (!$ENV{'QUERY_STRING'}) { print "Content-type: text/html\n\n"; print "Error: QUERY_STRING is null.\n"; exit 1; } $filepath = $ENV{'DOCUMENT_ROOT'} . '/' . $ENV{'QUERY_STRING'}; # *********************************************************************** # # * Put each line from the file into an array. As we do that, we also * # # * count the number of lines. * # # *********************************************************************** # open(F,$filepath) or die "$! \'$filepath\'"; $cnt = @line = ; close(F); # *********************************************************************** # # * Generate the random line number. * # # *********************************************************************** # srand(time | $$); print "Content-type: text/html\n\n"; print $line[int(rand($cnt))]; exit(0);