Do you really need for Perl to be able to detect that its output is being thrown away (and thus not bother copying it) or do you just not want the output? How many times per minute does this need to run, and how many megabytes of data does it add up to that you're throwing away total? Because, if you just don't need the output, you can save yourself a good deal of messing around by just calling system in void context.

do_stuff(); system($command, @args); do_more_stuff();

In theory Perl _could_ detect that system is called in void context not as the last item in the block and so could optimise away copying the command's output. In practice I don't know whether it does or not, but this only matters if you have a significant performance or footprint issue due to the size of the output being large or the system call being repeated quite often. If not, do it and don't sweat it. Don't optimise things that don't need to be optimised; it makes your code that much longer and less clear for no good reason.


{my$c;$ x=sub{++$c}}map{$ \.=$_->()}map{my$a=$_->[1]; sub{$a++ }}sort{_($a->[0 ])<=>_( $b->[0])}map{my@x=(& $x( ),$ _) ;\ @x} split //, "rPcr t lhuJnhea eretk.as o";print;sub _{ord(shift)*($=-++$^H)%(42-ord("\r"))};

In reply to Redirecting STDOUT by jonadab
in thread Redirecting STDOUT by mifflin

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.