[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Flushing all Buffers Before Exiting



Lee <ler762@gmail.com> writes:
> https://unix.stackexchange.com/questions/25372/turn-off-buffering-in-pipe/
> 
> Regards,
> Lee

	Thank you and all others.  It turns out that getting the
autoflush to work in perl is on a par with falling off of a log
for ease of execution.

	There is a perl variable called $| which, when set to a
non-0 value can cause an immediate flush of a buffer but perl
experts recommend you not do it that way.  It's even clearer.

	At the beginning of your perl program you add a line

use IO::Handle;

That is like an include in C so the perl language handler will
know what you mean when you add the next line right after you
write to your file:

FH->autoflush(1);

FH is just my example name for the open file handle.  Perl custom
is to use all caps for the name of the file descriptor so FH or
LOGDATA refers to that file and flushes that buffer.

	In this case, it is an endless loop so the buffer gets
flushed after every new write, but that's how you make it happen.

Martin


Reply to: