Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

RE: Post Election Day Perl

by Fastolfe (Vicar)
on Nov 09, 2000 at 02:55 UTC ( #40649=note: print w/replies, xml ) Need Help??


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'.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://40649]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2020-01-28 06:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?