Until now I've always tried to use grep, map, qx and other
functions that return values "properly", by not using
them in a void context (i.e. by not letting them waste time and memory by accumulating a result that will just be thrown away). I've started to question this behavior though.
After all, the FAQ says...
What's wrong with using grep or map in a void context?
Both grep and map build a return list, regardless of their context. This means you're making Perl go to the trouble of building up a return list that you then just ignore. That's no way to treat a programming language, you insensitive scoundrel!
Now I guess my question is: "Why is perl bothering to accumulate results when it knows it's being called in a void context?" For example, I've written backticks/system replacements that add additional features I like (e.g. like
logging). I've had them check the context (with wantarray), and not even accumulate output if called within
a void context. Why can't Perl do the same thing, and
leave me with a clear conscience about being lazier than I am now?