in reply to Re^2: map in void context
in thread map in void context
But that shows more about you than...
That's part of why I used the word "personally".
In the code at $work right now, I find this (variable names changed to protect the guilty):
map { push @result, $_ if $_ } @{ $obj->method };
Why was this not written as...
push @result, grep { $_ } @{ $obj->method };
In fact, why would I ever have push as the only thing inside a map (a pattern I see repeated throughout code written by this programmer)? Maybe there used to be more code there that made that make sense?
Code should have some semantic meaning beyond the nuts and bolts of what it does. To me, map means "transform one list into another list". It does that using a loop, and so it can be used more generally for looping (like the other constructs you mention), but it has a specialty. I'd say the same thing about grep, which, in void context, is identical to map.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: map in void context
by JavaFan (Canon) on Dec 17, 2008 at 16:29 UTC | |
by gwadej (Chaplain) on Dec 17, 2008 at 18:46 UTC |