in reply to Re: Re (tilly) 4: How do I remove an element from any array while iterating over it in a loop?
in thread How do I remove an element from any array while iterating over it in a loop?
Most people find the second much more readable. If you don't see why, then I suggest grabbing some co-workers, showing and explaining both, and trying to explain to them why they should find map more readable...@filtered = map {$_ eq $unwanted ? () : $_} @original; @filtered = grep {$_ ne $unwanted} @original;
Remember, generality often conflicts with readability. map is a far more general and complex function than grep. As such, when you see it you need to read very carefully, because a small detail can make a huge difference. But straight filtering is a very common need, and in that common case grep is simpler to write and easier to read.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re (tilly) 6: How do I remove an element from any array while iterating over it in a loop?
by John M. Dlugosz (Monsignor) on Aug 31, 2001 at 08:06 UTC |