Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flushing the Buffer

Status
Not open for further replies.

teky

Programmer
Mar 24, 2000
55
US
Hello Everybody,

Is there anyway we can flush the buffer in a log file in perl.

Thanks,
Teky.



 
$| = 1 flushes the STDIO buffer after each write. Hope you've tried this? There's always a better way...
 
$| = 1;

that's sets the *current* default file handle to auto-flush -- so if you want to set anything but STDOUT to auto-flush you have to do something like

open(LF,">log_file.txt") || die "error, $!\n";
select(LF); $|=1; Mike
________________________________________________________________

"Experience is the comb that Nature gives us, after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
I encountered this exact same need last Wednesday. I was most comfortable using the following method, which is included as part of the standard perl distribution... also, I feel that it's a bit more indicative of the intent, rather than doing multiple selects in your code:
Code:
use IO::Handle;  

open(FILE, ">>somefile.txt");

FILE->autoflush(1);  # This is the magic.

# and then continue on with your day...
Hope this helps...

--jim
 
ahh -- that'd be these new-fangled objekt things that I should get around to learning.... :)


(quite right Jim, much neater) Mike
________________________________________________________________

"Experience is the comb that Nature gives us, after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Thank you very much.
I could now flush the Log file.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top