in reply to open - Unbuffered Write???
Buffering is on by default. It can be turned off. The following will cause DAT to be flushed after every print:
open(DAT, '>', ...) || die(...); { my $old_sel = select(DAT); $| = 1; # Auto-flush. select($old_sel); } ...
If you don't want it to be automatic, use
sub flush { my $h = select($_[0]); my $af=$|; $|=1; $|=$af; select($h); } flush(*DAT);
Alternative, IO::Handle provides methods flush, autoflush and printflush, so you could use child class IO::File to open the file:
my $dat = IO::File->new($filename, 'w') or die(...); $dat->autoflush(1); print $dat ...; # Auto-flushed. $dat->print(...); # Auto-flushed. $dat->autoflush(0); print $dat ...; # Not flushed. $dat->print(...); # Not flushed. $dat->flush(); # Flushed. $dat->printflush(...); # Flushed.
By the way, you see the data when it's sent to the screen because STDOUT is buffered in a special way: Printing a newline causes a flush, even if autoflushing is off for that handle.
|
|---|