Monks,

Here's my delima; im working on a script that uses a handy piece of code from the cookbook that more or less does a tail (-f) on my logfile. From there I process each line of the log as it comes in, for various reporting. My question is, how do I efficently remove lines from this logfile; for example if they match one of my regex's?

I have tried using the Tie::File module, but after some initial testing it does not seem to be the most effective means of accomplishing my goal. The log file I am processing grows very quickly, and it didnt keep up as well as I believe it should. My second idea was to use the truncate function and remove the line this way, however I have not been able to get it to work properly. My output is always the first line of my pattern match, then the rest of the file is truncated.

...if regex... seek(LOG,0,0) || die "Seek error: $!"; ...process line... truncate(LOG,tell(LOG))

Im sure there is something simple I am missing - or perhaps there's a better way to go about accomplishing this task. Any feedback would be greatly appreciated.

Cheers, Ev

Good judgement comes with experience. Unfortunately, the experience usually comes from bad judgement.

In reply to removing lines from a file by ministry

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.