How is setting $| = 1 going to avoid buffering problems when calling system() on a non-Perl program?

I believe you are referring to fork(), and exec(), not system(). I also believe that modern versions of Perl include special code in fork() and exec() to implicitly flush all open file handles.

UPDATE: After discussing with grantm, the problem that he was dealing with in the past was a parent process expecting output from the perl script and a child of the perl script in the proper order, such as would be the case for a CGI that wishes to insert the output of a shell command directly into the HTML at a certain point. In this case, in order for the parent to see the output in the correct order, the output must be flushed before the shell command is executed. At least Perl 5.8.0 does this automatically for all systems that support the 'flush all handles' semantics (often fflush(NULL)). I recommend not using auto-flushing for CGI handles as it unnecessarily breaks the writes up into separate system calls, leading to inefficient web page serving. Flush when necessary, and let Perl autoflush when necessary.


In reply to Re: Re: Using perl to call a shell command? by MarkM
in thread Using perl to call a shell command? by Eccentric

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.