Perl - Flush file handler without print its content (149 Views)
Reply
Occasional Visitor
kazerm
Posts: 1
Registered: ‎06-23-2009
Message 1 of 2 (149 Views)

Perl - Flush file handler without print its content

Is there a way to flush a filehandler in perl without print it?

I'm using open inside of fork command inside foreach command:
foreach (){
fork(){
open ($cmd);
}
}
and if I'm printig the filehandler content - the script waits till the file ends before it start an new loop (of the foreach) - I want to avoid this - I need to fork the commands one after the another without waitting, but if I'm not printing the filehandler content - the buffer is getting full and the program get stuck.

Any idea how to solve this?

Thanks
Honored Contributor
H.Merijn Brand (procura
Posts: 6,188
Registered: ‎10-13-1997
Message 2 of 2 (149 Views)

Re: Perl - Flush file handler without print its content

You can set a filehandle to autoflush

use IO::Handle;
$fh->autoflush (1);

or

select ((select ($fh), $| = 1)[0]);

Either that, or flush forced

use IO::Handle;
$fh->flush;

Hope this helps

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.