in reply to Handling program output in real time

Here is the fact behind what you observed: there are actually two types of buffering mechanism: line buffering and block buffering.

When you print to STDOUT:

By setting $| as Anonymous Monk indicated, you force the output to be flushed after each write.

  • Comment on Re: Handling program output in real time