in reply to Re: Re: nonblocking I/O - testing whether file has more data to read
in thread nonblocking I/O - testing whether file has more data to read

If File::Tail detects no activity in the file, it will check it rarely. You can configure any interval, but I think the default is once per minute.

In my opinion, for something like a whole bunch of rarely updated files, File::Tail is the right thing. The code would look somewhat like this:

foreach (keys %files) { push(@tails,File::Tail->new(name=>$_,tail=>0,reset_tail=>0)); } while (1) { ($nfound,$timeleft,@pending)= File::Tail::select(undef,undef,undef,$timeleft,@tails); foreach (@pending) { my $line=$_->read; process($line); } }
This is actualy extracted from a script I use to monitor a whole bunch of logs on fairly active servers - the script calls one or more handlers which parse each particular type of log file, and the aggregate results are sent to a central monitoring machine. I ripped out the complications that deal with monitoring no files (because I colllect other data, too), and the multiple handler dispatch.
  • Comment on Re: Re: Re: nonblocking I/O - testing whether file has more data to read
  • Download Code