http://www.perlmonks.org?node_id=40649


in reply to Post Election Day Perl

Without using any advanced obfuscation techniques that might make this smaller...
use LWP::Simple;$_=get('http://www.cnn.com');($P,$u,$l)=m~(Bush|Gore)< +/\S+\s*<td\s*\S+ \S+edhead">([\d,]{9}).*?([\d,]{9})~s;$u=~s/,//g;$l=~ +s/,//g;$d=$u-$l;print$d?"$P leads by $d votes!\n":"Tie!\n";
Update: This does everything requested, and can be made smaller by taking out white space (~25 bytes) (I followed Chromatic's example by keeping it in there) and/or removing the dependency on 'use strict' (~25 more bytes). :) 571 bytes.
#!/usr/bin/perl -w use strict; use LWP::Simple; use Mail::Mailer; my($P,$u,$l)= get('http://www.cnn.com')=~ m~(Bush|Gore)</\S+\s*<td\s*\S+ \S+edhead">([\d,]{9}).*?([\d,]{ +9})~s; $u=~s/,//g; $l=~s/,//g; my $d=$u-$l; print $d?"$P is leading by $d votes\n":"It's a tie!\n"; open(F,(-f'votes'?"+<":">")."votes"); my @v=<F>; chomp(@v); if ((split(/\t/,$v[-1]))[2]!=$d) { print F localtime()."\t$P\t$d\n"; open(F,"<emails"); chomp(@v=<F>); $l = new Mail::Mailer; $l->open({To=>join(",",@v)}); print $l $d?"$P is leading by $d votes\n":"It's a tie!\n"; $l->close; }
Put a list of users/email addresses (comma-separated or line-separated) in 'emails' and run. It will report the current winner and the margin of votes and if this is different from last time, it will send an e-mail to everyone with the new information. Keeps a log of each change in 'votes'.