in reply to simple print question

You want to use the $| variable, as described in perldoc perlvar:

       $|      If set to nonzero, forces a flush right away and
               after every write or print on the currently
               selected output channel.  Default is 0 (regardless
               of whether the channel is really buffered by the
               system or not; $| tells you only whether you've
               asked Perl explicitly to flush after each write).
               STDOUT will typically be line buffered if output
               is to the terminal and block buffered otherwise.
               Setting this variable is useful primarily when you
               are outputting to a pipe or socket, such as when
               you are running a Perl program under rsh and want
               to see the output as it's happening.  This has no
               effect on input buffering.  See "getc" in perlfunc
               for that.  (Mnemonic: when you want your pipes to
               be piping hot.)
--
b10m

All code is usually tested, but rarely trusted.

Replies are listed 'Best First'.
Re: Re: simple print question
by Art_XIV (Hermit) on Mar 26, 2004 at 16:08 UTC

    Yeah, what b10m said.

    Under normal circumstances, Perl will 'buffer' STDOUT by 'saving' writes to it until there is a whole line, and then write that line in one swoop. It does this to improve performace, but, as you are finding out, it's not what you always want.

    Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"