Send As SMS

2/16/2006

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:

Randal L. Schwartz said...

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.

2/16/2006 12:31:08 PM  
Lawrence David said...

thanks for the note randal - i've modified my original post accordingly.

2/16/2006 02:50:35 PM  

Post a Comment

Links to this post:

Create a Link

<< Home

My blog has moved! Redirecting...

You should be automatically redirected. If not, visit http://stinkpot.afraid.org:8080/tricks/ and update your bookmarks.