Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

Perl - Flush file handler without print its content

Highlighted
kazerm
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
H.Merijn Brand (procura
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