http://www.perlmonks.org?node_id=1059106


in reply to Re: How can I add all the numbers in an array with out doing a foreach loop?
in thread How can I add all the numbers in an array with out doing a foreach loop?

While these will "work", they confuse the issue of what you are trying to accomplish.

grep is used to select items from a list.

map is used to transform one list into another.

Both take one list and return another list. In my opinion, using grep or map for tasks outside of that scope is being 'too cute', and will cost time later when maintenance time comes around. It takes more work (albeit not much) to comprehend the intent of these code blocks. Make it easier on your future-self and avoid using map and grep for this purpose.

--MidLifeXis