in reply to Re: Trouble with an array inside a format call
in thread Trouble with an array inside a format call

STDERR is not buffered while STDOUT is and thus the order of the stuff on the screen won't reflect the actual time sequence of events unless you turn the buffering off.

I think this is misleading advice. STDOUT is line buffered. I skimmed all of the statements which print to STDOUT, and I don't believe your advice will have any effect.

  • Comment on Re^2: Trouble with an array inside a format call

Replies are listed 'Best First'.
Re^3: Trouble with an array inside a format call
by Marshall (Canon) on Oct 17, 2009 at 02:48 UTC
    I certainly can't rule out some kind of OS or installation specific thing that makes your setup different than mine. I am using WinXP and ActiveState 5.10, although I know from experience this is the same on ActiveState 5.6.

    Here is a simple test program. Try it on your machine and see if you get the same results.

    #!/usr/bin/perl -w use strict; $|=1; #test was run with and without this statement #this turns buffering off print "this is a test\n"; print "this is a test2\n"; print STDERR "this is an error after line2\n"; print "this is a test3\n"; print "this is a test4\n"; __END__ Prints: without $|=1........ this is an error after line2 this is a test this is a test2 this is a test3 this is a test4 Prints: Now with $|=1 ...... this is a test this is a test2 this is an error after line2 this is a test3 this is a test4
    The STDERR message gets printed first because the lines from STDOUT haven't gone to the screen yet.

    Using $|=1 decreases I/O performance by maybe 30% or something like that. Normally of no consequence unless you are doing a lot of output or are trying to get the time sequence of things right.

    Update: deleted few lines about my version of tee.pl as there is a similar topic going on in another thread and I got them confused. Re^3: Getting user input with STDOUT tee to file.

      I certainly can't rule out some kind of OS or installation specific thing that makes your setup different than mine.

      I don't know a thing about Windows I/O, but the program behaves the same way (as I expect) on Linux with and without $| = 1;.