in reply to Re^5: trying to implement file tail with regular expression
in thread trying to implement file tail with regular expression

again thanks for your support. I tried your code but I faced the same issue. when its reaching while (my $line = <DIAG>) its stop. I am using Eclipse for step by step troubleshooting. I dont understand why this is happening. without using the file tail class it works fine and I was able to read from the file!!!!!! do you have any other idea please?

  • Comment on Re^6: trying to implement file tail with regular expression

Replies are listed 'Best First'.
Re^7: trying to implement file tail with regular expression
by poj (Abbot) on Feb 17, 2016 at 07:40 UTC

    Perhaps try it without tie.

    #my $ref = tie *DIAG,"File::Tail",( # name => $Config->{'_'}{'DIAGFILE'}, # interval => 1, # wait at start # maxinterval => 10, # change to suit # adjustafter => 10 # change to suit #); my $fh = File::Tail->new( name => $Config->{'_'}{'DIAGFILE'}, interval => 1, # wait at start maxinterval => 10, # change to suit adjustafter => 10 # change to suit ); my $restart; #while (my $line = <DIAG>) { while (my $line = $fh->read) { print $line; if ($line =~ /is higher than 5 seconds/) { . .

    This was the log generator I use to test the script

    #!perl use strict; my $n = 3; my $s = 10; print "Log generator running .. $n events every $s secs .. \n"; open OUT,'>','c:/temp/diag.log' or die "$!"; select OUT; $|=1; while (1){ print STDOUT scalar localtime."\n"; for (1..$n){ print scalar localtime,"- abc is higher than 5 seconds xyz\n"; } print scalar localtime."- some other log message $_\n" for 0...rand( +10); sleep($s); }
    poj

      same thing once it reach while (my $line = $fh->read) it stop. :(

        Do you mean it does not read new lines as they are added to the file ?