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?

bluto


In reply to Insensitive Scoundrel by bluto

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.