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:
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.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); } }
In reply to Re: Re: Re: nonblocking I/O - testing whether file has more data to read
by matija
in thread nonblocking I/O - testing whether file has more data to read
by hv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |