| [reply] |
Would you explain what "$|++" meaning is in the code? Thanks
Its like $foo++ except working on the variable $| , a reall shell-ish (or hack-ish) way to turn autoflush on, as in
use IO::Handle;
print 1; # doesn't print, puts 1 in the buffer
STDOUT->autoflush(1)
print 1; # prints 1 immediately (and the previously buffered 1)
print "\n2\n"; # \n forces a flush
Tutorials: Input and Output: Suffering from Buffering? | [reply] [d/l] [select] |
| [reply] [d/l] |
Just think me as a kid. When i run the below script, it really print 1(not as your comment).
Well, that is not my code ;) buffering means printing doesn't happen immediately, it is delayed, barring a crash of some sort, it will happen eventually, like when a program exits, when all buffers are flushed .
Try this instead
use IO::Handle;
print "\n2\n"; # \n forces a flush, 2 printed immediately
print 1; # doesn't print, puts 1 in the buffer
sleep 1; # still nothing printed
STDOUT->autoflush(1); # buffered 1 printed
print "\n"; # prints immediately
sleep 1;
print 1; # prints 1 immediately
sleep 1;
print "\n";
Without sleep, you wouldn't notice the buffering, and without sleep, I forget to add sleep or test my original code:) but its ok since I linked to the tutorial for you to read, and run its code, and believe what it says is true :) because it is :) I did, I did taw a puddy tat
| [reply] [d/l] |