#!/usr/local/bin/perl -w # # $Id: rand_text.pl,v 1.10 2002/06/01 09:16:50 nickjc Exp $ # use strict; use CGI qw(header); use vars qw($DEBUGGING $done_headers); # this script is amended from the freely available original script found at: # http://nms-cgi.sourceforge.net/ # adapted by Ray Baldwin # Configuration # # $DEBUGGING must be set in a BEGIN block in order to have it be set before # the program is fully compiled. # This should almost certainly be set to 0 when the program is 'live' # BEGIN { $DEBUGGING = 0; } my $random_file = 'lineonly.txt'; my $delimiter = "\n"; # End configuration # We need finer control over what gets to the browser and the CGI::Carp # set_message() is not available everywhere :( # This is basically the same as what CGI::Carp does inside but simplified # for our purposes here. BEGIN { sub fatalsToBrowser { my ( $message ) = @_; if ( $main::DEBUGGING ) { $message =~ s//>/g; } else { $message = ''; } my ( $pack, $file, $line, $sub ) = caller(1); my ($id ) = $file =~ m%([^/]+)$%; return undef if $file =~ /^\(eval/; print "Content-Type: text/html\n\n" unless $done_headers; print < Error

Application Error

An error has occurred in the program

$message

EOERR die @_; }; $SIG{__DIE__} = \&fatalsToBrowser; } open(FILE, "<$random_file") or die "Can't open $random_file: $!\n"; my @phrases; { local $/ = $delimiter; chomp (@phrases = ); } my $phrase = $phrases[rand(@phrases)]; print header(-type => 'text/plain'); $done_headers++; print $phrase; close(FILE);