Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( #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 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 taking refuge in the Monastery: (1)
As of 2021-10-23 02:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (86 votes). Check out past polls.

    Notices?