Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Parsing a log file

by nuance (Hermit)
on Jul 13, 2000 at 00:19 UTC ( [id://22269]=note: print w/replies, xml ) Need Help??


in reply to Parsing a log file

You've said you know how to read the files and get the lines etc. so I'm just going to do the other bits.

First you want to split the data to extract the path to the file and the number at the end. You can use split to do this:

my @bits = split ' ', $line;

This will give you and array with the path to the file in $bits[3] and the number in $bits[4]. Next you must extract the file type from the path to the file.

$bits[3] =~ s/\.(\w+)$/$1/;

I would then use a hash to store these:

$count{$bits[3]}{$bits[4]}++;

The first time you reference a type/ number combination it will be created with a value of one, each time after that the number gets incremented and so it keeps a count of how many times each combination occurred. At the end of the script you can get the data with:

foreach $type (keys %count) { foreach (keys %count{$type}) { print "$type $_ $count{$type}{$_}"; } }

Nuance

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://22269]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2025-04-30 00:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.