in reply to Reading a file live!

How can i do this without blocking my master script?

see Proc::Background and Poll :) non-blocking is called polling

for example

use Proc::Background; my $proc1 = Proc::Background->new($command, $arg1, $arg2); while( 1 ){ sleep 1; my $newsize = -s $fhorfilename; # if( ( $newsize - $oldsize ) > $minimum ){ if( ( $newsize - $oldsize ) > $buffersize ){ } my $readed = read $fh, $buffer, $buffersize; doStuff( $readed , $fh, $buffer, $buffersize ); ... last if not $proc1->alive; }

Replies are listed 'Best First'.
Re^2: Reading a file live! (poll)
by negativ_m (Novice) on Mar 07, 2014 at 08:24 UTC

    Hello,

    Thank you for the suggestions.

    But do you know another way to do it, without using this modules (Proc and Schedule) ?

    Thank you

      Of course, you don't have to use Proc::Background, it's just a nicety and saves you dealing with all the low-level wrangling involved with using fork in a robust fashion. But by all means feel free to use fork natively if you would rather. TIMTOWTDI, after all.

        Hi,

        Ok thank you for the advice.

      But do you know another way to do it, without using this modules (Proc and Schedule) ?

      Why? Maybe I'll have some ideas :)

      But, this is like the lowest common demoninator of portability and ease :)

        :) I will try to not complicate my life.