Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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...

Replies are listed 'Best First'.
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.

      zz zZ Z Z #!perl

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://496090]
NodeReaper edits tomorrow's obituaries

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2018-07-20 18:26 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (439 votes). Check out past polls.