Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
This could be made shorter by removing whitespace, but as the interpreter doesn't care about it, I don't think it should count.

Also, I focused only on the Florida count, as that's what I thought Fearless Perl Commando meant. (Yes, that's his title at EDC.)

#!/usr/bin/perl -w use LWP::Simple; my ($c, %d, @o) = get("http://www.cnn.com/ELECTION/2000/results/FL/ind +ex.html"); for ('Bush', 'Gore') { if ($c =~ m!$_</a>.+?dPercent">([0-9,]+)!s) { ($d{$_} = $1) =~ tr/,//d; } } @o = sort { $d{$a} cmp $d{$b} } keys %d; my $d = "$o[1] leads $o[0] by @{[($d{$o[1]} - $d{$o[0]})]} votes!"; $d = "It's a tie!" if $d{$o[1]} == $d{$o[0]}; die unless open(I, "vote.log"); @o = <I>; $_ = $o[-1]; exit if (/$d$/); select O if (open(O, ">>vote.log")); print (localtime() . "\n$d\n"); exit if !(open(A, "addresses")); my @a = <A>; die "No sendmail!" unless open(S, "|/usr/lib/sendmail -t"); print S <<E; Subject: Vote results as of @{[ ''. localtime() ]} Bcc: @{[@a]} $d E

Update: Hmm, what's the proper balance between error checking, graceful degradation when CNN changes the page format, and Doing the Right Thing with as few errors as possible? This would make a good Discussion.

/msg me your thoughts.


In reply to RE: Post Election Day Perl by chromatic
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 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?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 19:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found