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

Re^6: modify the contents of an array

by blazar (Canon)
on Sep 29, 2005 at 13:06 UTC ( #496090=note: print w/ replies, xml ) Need Help??


in reply to Re^5: modify the contents of an array
in thread modify the contents of an array

briefly, map and grep are to be used for their return value. Or else a for loop will do. Even the perlstyle page mentions that...


Comment on Re^6: modify the contents of an array
Download Code
Re^7: modify the contents of an array
by Anonymous Monk on Sep 29, 2005 at 13:35 UTC
    Eh, no, you completely misunderstand the purpose of perlstyle. Perlstyle lists Larry's preferences of how he codes. And there's only one thing he strongly cares about - which isn't the map issue. The remark you quote is listed under Here are some other more substantive style issues to think about.

    It's telling you to think about map/grep in void context - not ordering you to avoid it. But what's more important is the reasoning - it's referring to the fact that map in void context is expensive. And it was - at the time perlstyle was written. But perlstyle was written many years ago, long before the map issue was fixed. It's fixed now, so there's nothing left over from the reasoning in perlstyle.

      uh, seriously, wtf?
      map { s/// } @array; # ... s/// for @array;
      They're the same, except one is more confusing to read, because most people expect it's return type to be used.

      Just because larry likes something is not a reason everyone should be following him (we should all be blindingly following Perl Best Practices instead ;-), but map in void context has no advantage over for, but does add an element of confusion (did the author mean to assign to a result array? did the author not know about for? am I reading this badly? let me go up one line and see if it's a multi line assignment statement).

      Optimizing for readability is universal good style.

      -nuffin
      zz zZ Z Z #!perl

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://496090]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2014-12-26 04:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (165 votes), past polls