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

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

Replies are listed 'Best First'.
Re^8: trying to implement file tail with regular expression
by Anonymous Monk on Feb 17, 2016 at 08:11 UTC

    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 ?

        when I am performing debug in Eclipse and I click on step over button to check each line of the code, once it reach while(my $line = $fh->read) and i click on step over it stop at this point and i cannot proceed in the script. so answering your question I dont thing its reading even the first line in the file