If you put a print statement inside of a loop that runs really really quickly, you won’t see the output of your print statement until the program terminates.

The solution to this problem is to “flush” the output buffer after each print statement.

Where $| is non zero, it tells print to flush the buffer on the next output.

This should be used within the looping print statement, see the examples below.


$| = 1;
for($i=0;$i<10;$i++){
print “=”;
sleep 1;
}
print “\n”;

$| = 0;
for($i=0;$i<10;$i++){
print “=”;
sleep 1;
}