#!/usr/bin/perl package footiebot; # footiebot use LWP::Simple; use HTML::Parser; use Data::Dumper; use strict; use vars qw{$score $scorepage @scorestore @alltext $team}; # {{{ text sub text1 { my($text) = @_; push @alltext, $text; # print $text; if ($text =~ /$team/i) { if ($alltext[$#alltext - 1] =~ /\d+ - \d+/) { # last entry is a score, playing away @scorestore = @alltext[($#alltext - 2)..$#alltext]; } else { # playing at home - need to get 2 more push @scorestore, $text; } } elsif ($#scorestore > -1) { # playing get home - get those 2 more push @scorestore, $text; } if ($#scorestore == 2) { # score array is complete $score = join " ", @scorestore; } } # }}} # {{{ get_score sub get_score { $team = shift; $team ||= 'england'; $score = undef; $scorepage = get('http://www.livescore.co.uk'); my $p = HTML::Parser->new( api_version => 3, text_h => [\&text1, "dtext"], marked_sections => 1 ); $p->parse($scorepage); if ($score) { return($score); } return("No score retrieved"); } # }}} 1;