#!/usr/bin/perl
use warnings;
use strict;
################################
# By: Ventz Petkov             #
# Date: 11-16-05               #
# Jokes 2 Go - Joke of the Day #
################################

use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
my $name = $ARGV[0];
my $url = "http://www.jokes2go.com/jtoday.html";
$mech->agent_alias( 'Mac Safari' );
$mech->get( $url );
my $page = $mech->content;
$page =~ /.*<font class="bigtitle">Today's jokes <font color="darkblue">(.*)<\/font><\/b><\/font>.*/s;
print "Today's jokes: $1\n";
print "#" x 50; print "\n\n";

my @pages = split("\n", $page);

for(@pages) {
    if($_ =~ /.*<!-- DBNUM: (.*) -->.*/) {
        $url = "http://www.jokes2go.com/cgi-perl/sendfrienddb.cgi?jokenum=$1";
        $mech->get($url); $page = $mech->content;
        $page =~ s/.*<pre class=\"small\">(.*)<\/pre>.*/$1/s;
        chomp($page); print "$page\n";
        print "#" x 50; print "\n";
    }
}
exit;

