Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

Perl - Flush file handler without print its content

Occasional Visitor

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
1 REPLY
Highlighted
Honored Contributor

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