flush perl's print buffer
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:
$|++;[update]
as has been pointed out by r. schwartz, i've misspoken; the above command causes print to flush the buffer preceding the next output.
2 Comments:
Actually, you can also use "$| = 1" to do that, and some would consider that a bit less obscure.
Also, that doesn't flush the buffer. It tells print to flush the buffer on the next output. I think you know that, but it might not be clear reading that.
thanks for the note randal - i've modified my original post accordingly.
Post a Comment
Links to this post:
Create a Link
<< Home