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.
In reply to Re: Handling program output in real time
by pg
in thread Handling program output in real time
by dvergin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |