Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > Perl

Reply
 
LinkBack Thread Tools Display Modes
Old 04-03-2003, 09:58 AM   #1 (permalink)
token
Registered User
 
Join Date: Apr 2003
Location: Atlanta
Posts: 2
token is on a distinguished road
Counting things while going into an array

I've just come up stumped on this one.

Basically, I'm parsing a log file. I want to count each time an occurence of something is in the file. I can open the file and read it in...it's just the counting part I can't figure out. I want to end up with something like this:


this_thing - 200 times
that_thing - 12 times
other_thing - 156 times


Any suggestions?
token is offline   Reply With Quote
Old 04-03-2003, 10:25 AM   #2 (permalink)
Talleyrand
Registered User
 
Join Date: Mar 2003
Location: Seattle, WA
Posts: 7
Talleyrand is on a distinguished road
Send a message via ICQ to Talleyrand
I like to use hashes for this ... keeps things (mostly) neat while keeping track of data. Be careful, though, hashes can get out of hand if you go nuts with 2+ dimensions


So like, you'd have some hash %count
Each time what you want is hit, you'd increment the appropriate key...

$count{'this_thing'}++

And if what you're coming across is variable, you can use whatever is set in the variable as a key name ... this works well for pattern matches.

my ( $pattern ) = $log_line =~ /(some pattern)/;
$count{$pattern}++;

Make sense?

Of course, with PERL, there's always more than one way to do it

Hope that helped.

Talleyrand
Talleyrand is offline   Reply With Quote
Old 04-03-2003, 06:10 PM   #3 (permalink)
token
Registered User
 
Join Date: Apr 2003
Location: Atlanta
Posts: 2
token is on a distinguished road
Yeah, I think that's pretty much what I was looking for. I can adapt that to my needs perfectly.

And yes, it will be variable data, but it will always be in the same format in the same place in the log file on each line. Apply a li'l regex and I'm good.

Thanks Much,

Token
token is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
working with Array Goong MS Technologies ( ASP, VB, C#, .NET ) 3 07-22-2004 12:14 PM
breaking down an array from a form metazai PHP 12 07-09-2004 06:18 AM
array max num Apodysophilia Java 9 04-10-2003 06:36 AM
Return an array with register_globals = off bdl PHP 7 03-10-2003 05:37 PM
adding to an array in php sde PHP 1 06-12-2002 11:04 AM


All times are GMT -8. The time now is 02:19 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting