Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

The blog post is a really interesting, and it shows something important about the programming ability of the writer.

The original Perl code worked, but it was a little clumsy. A visitor called Gavin wrote, essentially, a two liner out of it, then relented and wrote a cleaner version that was 15 lines long. But there were important differences between that version and the original Perl solution.

In the original solution, contact records were only discarded near the very end of the script, when in fact they could be discarded during the input loop. This would have saved storing and sorting unwanted records, and this is true in any language.

Similarly, in the original code, each record was extracted into an array, then a reference to that array was pushed into another array -- a named variable was created each time around the loop. It would have been more efficient to wrap the statement in square brackets and make it an anonymous array, which is what Gavin's solution did. it seems obvious -- if you're creating a variable inside a small scope and using it just once, why is it there at all?

Our own blazar (I presume) produces a very readable solution that is somewhat terse but very compact. brainspun produces a nice version but again it misses the point of filtering out unwanted records in the input loop.

There's even a great shell solution which is actually what I thought about the first time I read the blog. It's a very clean way of solving the problem, and that solution *does* check the 'contact me' bit first.

Great find .. thanks!

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds


In reply to Re: One Monasterian's Prodigal Journey by talexb
in thread One Monasterian's Prodigal Journey by bradcathey

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (10)
    As of 2014-12-25 19:14 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (162 votes), past polls