Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Comment on

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

I'm sorry. I appear to have added to the confusion, rather than clarifying. I should have begun by saying that I avoid using map or grep in void context.

What I was commenting on was your suggestion that the only reason for using those operators was that they are more concise and show a better grasp of Perl.

An example of what I was trying to say is the code example below.

my @minutes = map { $_ / 60 } @seconds;

In the foreach style, this would be

my @minutes = (); foreach my $sec (@seconds) { push @minutes, ($sec / 60); }

To me, the first signals the intent to transform a list of times in seconds into an equivalent list in minutes. The second has pretty much the same effect, but I have to read the code to see what the output is. In the first case, it seems obvious (to me, at least) that the output is the left side of the assignment.

Although this may seem like a simple example. I find many times that I can use these operators to reduce the noise characters in code like this. Sometimes that reduction is enough to make the overall code clearer by not spending space on relative minor pieces of logic.

Granted, if the code inside the block gets complicated enough, I may change to the foreach style to emphasize the fact that this is not a simple transformation.

I see this as a Perl idiom that can convey information to the maintainer when used carefully. I do agree that it can be horribly misused. (The less I say about that the better.<grin type="embarassed"/>

G. Wade

In reply to Re: Re: Re: Re: Think for yourself. by gwadej
in thread is the use of map in a void context deprecated ? by arno

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, 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
  • 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (6)
    As of 2018-06-23 16:48 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (125 votes). Check out past polls.