Sometimes, 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; sometimes, you don’t even see the output at all.
The solution to this problem is to “flush” the output buffer after each print statement; this can be performed in perl with the following command:
$| = 1;
Two examples to understand how it works:
$| = 1;
for ($i=0; $i<10; $i++) {
print “=”;
sleep 1;
}
print “\n”;
$| = 0;
for ($i=0; $i<10; $i++) {
print “=”;
sleep 1;
}
Also, printing “\n” flushes the buffer, which you can verify by modifying the last print statement from “=” to “=\n”.
Reference:
》http://www.kichwa.com/quik_ref/index.html