Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://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

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 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?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-24 19:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found