in reply to Screen Output Buffering

I'm surprised this hasn't been answered already. STDOUT in perl is buffered by default. To make sure STDOUT is autoflushed, set $| to a true value early in your program. STDOUT is not buffered by default.

If another file handle has been selected, you may need to select STDOUT before setting $|.

See perldoc perlfun and perldoc perlvar fore more information on flushing and $|.

hth,

Kyle

Replies are listed 'Best First'.
Re^2: Screen Output Buffering
by Limbic~Region (Chancellor) on Aug 19, 2004 at 21:39 UTC
    mortis,
    To make sure STDOUT is autoflushed, set $| to a true value early in your program

    I am sorry about nitpicking but setting $| to a true value will turn on auto-flushing for the currently selected file handle. I know it is being pedantic, but just because STDOUT is the default selected file handle doesn't mean it has to be:

    #!/usr/bin/perl use strict; use warnings; open (FILE, '>', 'foo.txt') or die "Unable to open foo.txt for writing + : $!"; select FILE; $| = 1; # FILE is now unbuffered print "hello, world\n"; print STDOUT "goodbye cruel world\n"; # still buffered

    Cheers - L~R

Re^2: Screen Output Buffering
by mvaline (Friar) on Aug 19, 2004 at 21:12 UTC
    Thanks! That worked. I guess I didn't grep perlfun and perldoc accurately enough. I appreciate the help.