1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
#!/usr/bin/perl -wT
#
# $Id: rand_text.pl,v 1.7 2002/01/27 17:35:28 davorg Exp $
#
# $Log: rand_text.pl,v $
# Revision 1.7 2002/01/27 17:35:28 davorg
# Removed some potentially confusing commented out code
#
# Revision 1.6 2001/12/01 19:45:22 gellyfish
# * Tested everything with 5.004.04
# * Replaced the CGI::Carp with local variant
#
# Revision 1.5 2001/11/25 11:39:38 gellyfish
# * add missing use vars qw($DEBUGGING) from most of the files
# * sundry other compilation failures
#
# Revision 1.4 2001/11/13 20:35:14 gellyfish
# Added the CGI::Carp workaround
#
# Revision 1.3 2001/11/13 09:17:37 gellyfish
# Added CGI::Carp
#
# Revision 1.2 2001/11/11 17:55:27 davorg
# Small amount of post-import tidying :)
#
# Revision 1.1.1.1 2001/11/11 16:48:57 davorg
# Initial import
#
use strict;
use CGI qw(header);
use vars qw($DEBUGGING);
# 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 = 1;
}
my $random_file = '/path/to/random.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;
$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";
print <<EOERR;
<html>
<head>
<title>Error</title>
</head>
<body>
<h1>Application Error</h1>
<p>
An error has occurred in the program
</p>
<p>
$message
</p>
</body>
</html>
EOERR
die @_;
};
$SIG{__DIE__} = \&fatalsToBrowser;
}
open(FILE, $random_file)
or die "Can't open $random_file: $!\n";
my @phrases;
{
local $/ = $delimiter;
chomp (@phrases = <FILE>);
}
my $phrase = $phrases[rand(@phrases)];
print header(-type => 'text/plain');
print $phrase;
close(FILE);
|