Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Syntactic Confectionery Delight
 
PerlMonks  

Comment on

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

As to the question of grep and map being used as much as they could, I couldn't agree more. At work, I've had to train a few people to use them instead of foreach when they made sense ... and then untrain them a bit when they started using them where they didn't make sense. The point isn't to religiously worship them, but to make your code do what it says: if you're converting one list into another, you're mapping from one to the other. If you're finding elements in a list, you're grepping for them.

By speaking idiomatically perl, you may get a speed benefit (as you did in your benchmark), but, more importantly, you get a maintenance benefit: your code looks like a design document!

That is actually part of the reason why I don't like map's and grep's used in void context - they are no longer reading like plain English. "Map from @common to ... nothing?" Instead, just use for/foreach: "For each element in @common, do..." That reads like exactly the solution you're attempting to do. Which is probably how you're thinking of the problem - and, any time your can code your solution in the domain of the problem instead of the domain of the solution, you're going to end up with clearer and more flexible code.


In reply to Re: question for perl book & magazine authors by Tanktalus
in thread question for perl book & magazine authors by jfroebe

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 perusing the Monastery: (5)
    As of 2014-04-21 09:02 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (492 votes), past polls