in reply to $|++ Does What, Exactly? (was: $++ Does What, Exactly?)
There are some scenarios where you want the output to not be buffered. For example, you have several processes writing to the same file and you don't want the output of one to clobber the output of another (the Apache web server is a good example).
Try this piece of code
You should get a long pause and then all of a sudden "10". Then on the next line you should get a steady count from 1 to 10. The reason is that the 1 - 10 is in the buffer and hasn't been flushed to the screen yet. When $| becomes set to 1, the buffer flushes and you get all the output so fast that all you see is the 10. On the next one, the buffer isn't used, so you see every number as it is printed.for (1..10) { print "$_\r"; sleep(1); } print "\n"; $| = 1; for (1..10) { print "$_\r"; sleep(1); } print "\n";
/\/\averick
|
|---|