in reply to Newline vs Return

Disable buffering on STDOUT by adding $| = 1; somewhere close to the top of your program.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Replies are listed 'Best First'.
Re^2: Newline vs Return
by DuaneCenveo (Initiate) on Oct 07, 2005 at 20:43 UTC
    Thanks, BrowserUK. That works! Duane
      That works!

      In case you were curious about why it works: filehandles are STDOUT is line-buffered by default. This means that when you print, the output is buffered until (1) the buffer fills up or (2) you print a newline. Disabling buffering makes it output right away.

      Update: correction as per ikegami's reply

        That's not quite true. Only STDOUT is line-buffered by default. In fact, only STDOUT is ever line-buffered(*). I verified this with the following snippet:

        perl -e "open(FH, q{>test}); print FH (qq{a\n}); sleep(5); print FH (q +q{a\n});"

        The lines only appeared after the 5 seconds were over.

        (*) Maybe XS or PerlIO can change this? Of course, tie could.