Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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'.

In reply to RE: Post Election Day Perl by Fastolfe
in thread Post Election Day Perl by vroom

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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 or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2021-10-23 18:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (88 votes). Check out past polls.

    Notices?