in reply to Buffered read and matching

a comment on
"Also be nice if I could pipe to it also so tail -f <LOG> | log_grepper.pl.. "
I use the following sample code structure to read files in a 'tail' ing fashion:
#!/usr/bin/perl -w my $targetF = "/var/log/local2"; for(;;) { open ML, "<$targetF" || die $!; #seek(ML, 0, 2); # to EOF - Not, process from beginning for (;;){ while (<ML>){ another_line(); } sleep 2; seek(ML, 0, 1); # reset end-of-file error } # dropping here with the 'last' should cause # the file being monitored to be closed and reopened close (ML); } sub another_line { # $_ has the line # Check for target phrases return; }
(I can't remember which book I found this in, but I find it very useful.)

But any cyclically incremental reading of the file adds the need for accumulation of multi-line events, handling partial (incomplete) lines, and all the other 'streaming' techniques.