Re: Spliting the log files
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Wed, 29 Aug 2007 22:04:57 -0700
sivasakthi wrote:
Hi All,
Hello,
I have used the following code to calculate from log files,
#!/usr/bin/perl
use strict;
use warnings;
use File::Tail;
my $file=File::Tail->new("/log/path");
my $line= undef;
You don't really need file scope for $line.
while (defined($line=$file->read))
You can limit its scope here:
while ( defined( my $line = $file->read ) )
{
my ($time,$lport,$ip,$stats,$rport) = split;
The current line is in the $line variable but you are splitting the contents of the $_ variable:
my ( $time, $lport, $ip, $stats, $rport ) = split ' ', $line;
If you only need the third field then you could write that as:
my $ip = ( split ' ', $line )[ 2 ];
print "$ip/n";
If you want a newline at the end it is spelt "\n", not "/n".
}
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.
- References:
- Spliting the log files
- From: Sivasakthi
- Spliting the log files
- Prev by Date: Spliting the log files
- Next by Date: Unable to locate make
- Previous by thread: Spliting the log files
- Next by thread: Unable to locate make
- Index(es):
Relevant Pages
|
|