The code you offer is certainly clearer to an individual who has perhaps first started writing in Perl, coming from another language, but I have to quibble with your statement that "it's best."

Part of learning a new language is learning its idioms. The implicit $_ is probably one of the most widely used idioms in Perl, and appears in almost every well-written script. By encouraging a new programmer to "pass by" that idiom, I think you make it less likely that the person will learn its use.

I would say that it is actually "best to say" what the new programmer will have to learn to program efficiently and to read scripts by other programmers. After all, particularly in this case, the implicit $_ is not a difficult concept. If the new programmer doesn't learn it here, then learning grep and map will only be that much more difficult.

As for the argument that one may introduce bugs if one starts using things like grep, it only becomes that much more likely that a programmer who is unfamiliar with the implicit $_ will make such errors if you try to "hide" its use from him/her in simpler structures.

-HZ

In reply to Re: Re: help with by HyperZonk
in thread help with the diamond operator by La12

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.