Nick wrote:
Hi There,
I am trying to analyze a simple log file and pull 2 pieces of data
from it. The log looks as follows:
www.example.com 42f3ca10 42f8c42f 0 7338
0 3638
Where each valie is tab seperated. I want to create a hash with
"www.example.com" as the key and column 5 (7338 in this example) as
the value. There will be lots and lots of lines hence me using foreach.
This is how I am attempting it:
#!/usr/bin/perl
use Data::Dumper;
@tmp = `cat /usr/local/apache/logs/tmp`;
foreach (@tmp) {
if
(/(^.+(\.net|\.uk|\.com|\.org))(\t[a-z0-9]{9})(\t[a-z0-9]{9})(\t[a-z0-9]{9})(\t[a-z0-9]{9})/)
{
$bw_usage{$1} = ( $6 );
}
}
print Dumper \%bw_usage;
Firstly, please don't laugh at my code too much! :o) Now I thought
this would put coulmn 1 into memory 1 and column 5 intom memory 6.
This does not seem to work at all and all I get is an empty hash!
Could anyone advise what I am doing wrong or if I am attempting this
is the wrong way?
Thanks, Nick
How about the following code ...
#!/usr/bin/perl -w
open FD, "/usr/local/apache/logs/tmp";
while (<FD>) {
$bw_usage{$1} = $2 if /([\w.]+)\s+\w+\s+\w+\s+\w+\s+(\w+).+/;
}
close FD;
foreach (keys %bw_usage) {
print "$_, $bw_usage{$_}\n";
}
--
Get Thunderbird <http://www.mozilla.org/products/thunderbird/>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>