#!/usr/bin/perl -w # Create a random pokey cartoon # Waider May 2000 use LWP::UserAgent; # 1. get the list of cartoons, so we know how many there are. # http://www.lysator.liu.se/pokey/archive/ $ua = new LWP::UserAgent; $ua->env_proxy(); $req = new HTTP::Request GET => "http://www.lysator.liu.se/pokey/archive/"; $res = $ua->request( $req ); if ( $res->is_success ) { $content = $res->content; } else { die "Can't get index page.\n"; } # Find the max number off the list ( $max ) = $content =~ m/^.*index(\d+).html\D+$/si; # Right, now let's make up a cartoon. If it's over four frames, we'd # better check if the frames exist. $frames = int( rand( 3 )) + 3; # 4 - 7 frames print <<"EOH"; Content-Type: text/html\n\n

EOH
for $i ( 0..$frames ) {
$i[ $i ] = int( rand( $max ) + 1 );
if ( $i > 3 ) {
# check if the frame exists
$req = new HTTP::Request HEAD =>
"http://www.lysator.liu.se/pokey/archive/pokey$i[$i]_" . ( $i+1 ) . ".gif";
$res = $ua->request( $req );
if ( $res->is_success ) {
# that's okay
} else {
print "\n";
last; # end the cartoon here.
}
}
print "
\n"; } print <<"EOH"; HELLO . POKEY THE PENGUIN LOVES TO READ YOUR EMAIL
POKEY THE PENGUIN IS COPYRIGHT © 1998 THE AUTHORS