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'.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.