----- Original Message -----
From: Nick <[EMAIL PROTECTED]>
Date: Thursday, August 11, 2005 10:37 am
Subject: Analyze Log

> Hi There,
Hi Nick,
> 
> 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.
Are you sure they are all tab separated ?? If this is a case, using <C> split 
would yield much more efficient code.

> 
> This is how I am attempting it:
> 
> #!/usr/bin/perl
always !!!
use strict;
use warnings;
> 
> use Data::Dumper;
> 
> @tmp = `cat /usr/local/apache/logs/tmp`;
Is there a reason for doing this externaly ? what happens if the cat fails ? 
are you sure your script is pulling in the data ??
> 
> 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 );
>     }
what happens if the match fails ? Are you sure it matches on all itterations ?
  else{ print "match failed \a\n!!";}

> }
> 
> 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?
I think my pointers above would tell you why it's failing. Here is an aproach I 
would take...

#!PERL
use warnings;
use strict;

my ($debug,%hash);
open RD,"/usr/local/apache/logs/tmp" or die "ERROR ON OPENING LOG!!\n";

while( <RD> ){
     my @tmp = split "\t";
        $hash{$tmp[0]} = $tmp[4];
        print join ":",@tmp if $debug;
}

HTH,
Mark G.
> 
> Thanks, Nick
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to