Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
How gauche, to respond to my own post. amelinda had the right idea with using lynx instead of LWP::Simple. Here's one that has whitespace and still weighs in at 557 bytes, performs the logging and mailing (but only if something has changed):
#!/usr/bin/perl $_ = `lynx -dump http://www.cnn.com/ELECTION/2000/results/FL/index.htm +l`; push @c, (/(Bush).{4}([0-9,]{9})/s), (/(Gore).{4}([0-9,]{9})/s); tr/,//d for @c[1,3]; $d = "$c[0] leads $c[2] by @{[$c[1] - $c[3]]} votes!"; $d = "It's a tie!" if $c[1] == $c[3]; die if !open(I, "vote.log"); chomp($_ = $i) while ($i = <I>); exit if (/$d$/); die if !(open(O, ">>vote.log")); $i = localtime(); print O ("$i\n$d\n"); die if !open(A, "addresses"); die if !open(S, "|/usr/lib/sendmail -t"); print S <<E; Subject: Vote results as of $i Bcc: @{[<A>]} $d E
Removing whitespace would take me down at least to 531. Of that, 29 characters are in the messages (someone leads, someone tied), 26 characters are used in filenames (I could get that down to 3), and the URL is 54 characters. Using +shift or @ARGV and the other optimizations could take me close to 400 bytes.

ph3@r!

Update:

Here's a version with some optimizations that occurred to me in the shower. (See, 'Where Do You Get Your Best Ideas?') It's a slim 516 bytes, without removing whitespace (30 characters or more), trimming filenames, removing error checking (27 characters), but it corrects a subtle flaw in the original.

#!/usr/bin/perl $_ = `lynx -dump http://www.cnn.com/ELECTION/2000/results/FL/index.htm +l`; push @c, (/(Bush|Gore).{4}([0-9,]{9})/sg); y/,//d for @c[1,3]; $d = "$c[0] leads $c[2] by @{[$c[1] - $c[3]]} votes!"; $d = "It's a tie!" if $c[1] == $c[3]; die if !open(I, "vote.log"); ($_ = $i) while ($i = <I>); exit if /$d/; die if !(open(O, ">>vote.log")); $i = localtime(); print O ("$i\n$d\n"); die if !open(A, "addresses") || !open(S, "|/usr/lib/sendmail -t"); print S "Subject: Vote results as of $i Bcc: @{[<A>]} $d";

In reply to RE: 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 avoiding work at the Monastery: (1)
As of 2021-10-23 03:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (86 votes). Check out past polls.

    Notices?