ministry has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: removing lines from a file
by polettix (Vicar) on Jun 22, 2005 at 17:46 UTC | |
|
Re: removing lines from a file
by rev_1318 (Chaplain) on Jun 22, 2005 at 18:33 UTC | |
by izut (Chaplain) on Jun 22, 2005 at 18:54 UTC | |
by polettix (Vicar) on Jun 22, 2005 at 20:53 UTC | |
by rev_1318 (Chaplain) on Jun 22, 2005 at 21:15 UTC | |
by ministry (Scribe) on Jun 23, 2005 at 14:27 UTC | |
|
Re: removing lines from a file
by g0n (Priest) on Jun 22, 2005 at 17:30 UTC |