|XP is just a number|
Re^3: Using grep in a scalar context (brains)by Anonymous Monk
|on Feb 07, 2013 at 12:14 UTC||Need Help??|
is rather extravagant ... would produce the same result. Am I missing something?
Not really, although, a clarity argument could be made
map is mostly used for generating lists, so sometimes it feels like the wrong tool for counting ( is the use of map in a void context deprecated ? , What's wrong with using grep or map in a void context? )
tobyink improves clarity by generating a list of counts and adding/summing them (makes an array of matches, scalar array is count), map made a list, feels good :)
you rely on generating a list of matches ( m//g) , and that map in scalar context returns a count
Is there a performance advantage? Penalty? Was map-in-scalar as expensive as map-in-void (before perlv5.8.1)?
Compare the "three"
If you're thinking in terms of map and grep, thinking perlishly, then you write it like it makes the most sense to you, feels most natural, reads instantly and effortlessly (reads like breathing), needs no thought ...
so what you're missing, is tobyink's brains