Like other have said, it is a buffering issue. In recent enough versions of Perl you can do:
use IO::Handle
STDOUT->autoflush()
I think this is cleaner than using the $|
variable, even if it will work in the same way.
The use IO::Handle
is needed to attach the autoflush
method to any future handle. And autoflush
has its quirks in the sense that without passing a value it assumes 1
as written in the perlvar
man page:
The methods each take an optional EXPR, which, if supplied, specifies the new value for the "IO::Handle" attribute in question. If not supplied, most methods do nothing to the current value--except for "autoflush()", which will assume a 1 for you, just to be different.