Re: performance efficient "tail"
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 12 Jan 2006 08:30:10 -0800
ytoledano@xxxxxxxxx wrote:
> Hi,
> I'm trying to write a script which parses the end of a 1GB log which is
> located on a remote server. Since the server isn't mine, I'm not
> allowed to run any scripts on it. Another problem is that it's
> complicated to use non-default modules since I have no Internet
> connection and using any mobile media requires special permission.
>
> How do I tail and parse the last X rows in the most efficient way,
> using existing modules? I don't mind first saving the "tail"ed text
> into a temp file.
>
> I access the logs at \\<IP>\d$\log, if it matters...
A remarkably similar question was just posted to comp.lang.perl.misc.
I would suggest using the standard Tie::File module, as in:
#!/usr/bin/perl
use strict;
use warnings;
use Tie::File;
tie my @file, 'Tie::File', '\\<IP>\d$\log'; #fix this line, obviously.
process_lines(@file[@file-25 .. $#file]);
sub process_lines {
my @lines = @_;
#do whatever you need to do with the last 25 lines of the file...
}
__END__
Paul Lalli
P.S. I'm relatively willing to bet David will have a better looking
solution using IO::All...
.
- Follow-Ups:
- Re: performance efficient "tail"
- From: ytoledano
- Re: performance efficient "tail"
- References:
- performance efficient "tail"
- From: ytoledano
- performance efficient "tail"
- Prev by Date: performance efficient "tail"
- Next by Date: Re: performance efficient "tail"
- Previous by thread: performance efficient "tail"
- Next by thread: Re: performance efficient "tail"
- Index(es):
Relevant Pages
|
|