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.


In reply to Re: Buffered read and matching by Wiggins
in thread Buffered read and matching by ropey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.