Are you on Unix? (not sure how WinXx reacts) Try this:
open T1, ">>test1.out"; open T2, ">>test1.out"; foreach (0..20) { print T1 "1:$_$/"; print T2 "2:$_$/"; } close T2; #notice close order... close T1; open T1, ">>test1.out"; open T2, ">>test1.out"; select T1; $|=1; select T2; $|=1; foreach (0..20) { print T1 "3:$_$/"; print T2 "4:$_$/"; } close T2; close T1;

The total output of the first for loop is smaller than the print buffers on most machines. You'll wind up with the lines out of order from what you'd expect because the data isn't actually written until the close flushes the buffer to disk.

With both the filehandles set to autoflush, the lines alternate the way you would expect. The benefit to caching is that you get better disk performance. The benefit to flushing is that you get the data written immediately. That can be a big deal if you have multuple time sensitive programs writing to one log file. Imagine if a webserver left caching on while writting the log. you'd get chunks of lines in order from each httpd child and then flip back 3 seconds for the next child's data rather than a smooth temporal stream of requests. Very ugly.

--
$you = new YOU;
honk() if $you->love(perl)


In reply to Re: $++ Does What, Exactly? by extremely
in thread $|++ Does What, Exactly? (was: $++ Does What, Exactly?) by Anonymous Monk

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.