in reply to Re: map in void context
in thread map in void context
Not that I've checked, but I recall a rumour that modern-enough perls (5.8.8, maybe) detect map in a void context and drop the list creation to save time and space. I don't see a point: the definition of map is "Evaluates ... and returns the list" whereas foreach (aka for) "is an iterator: it executes the statement once for each item". So map should return a list (it has explicit documentation regarding scalar context), and for shouldn't really have a return (or an accumulator).
And the map variant is actually only one char longer if you golf it right:
But I still prefer map for mapping, and for for iterating.$_++for@l map$_++,@l
|
|---|