I think the whole OO -v- procedural debate is mute. The problem remains the same regardless of the way you choose to code it. Personally, this seems like a straight forward hash problem, with the caveat that your 'primary key' is a combination of 3 fields, agency/url/module. You then need secondary keys of pass/fail/new/user. For the first three, you increment a count, for the fourth, create a hash with the user names as keys, and the use number accumulated as your Unique count.
Hmm. Words make that about as clear as mud. Maybe a little code will get you started.
#! perl -slw use strict; my %stats; while( <DATA> ) { my ($date, $user, $agency, $url, undef, $type, $module, undef) = s +plit ' '; $stats{"$agency $url $module"}{$type}++; $stats{"$agency $url $module"}{user}{$user}=undef; } for my $key ( sort keys %stats ) { my ($agency, $url, $module) = split ' ', $key; printf "%8s %5s %3d %3d %3d %3d %s\n", $agency, $url, $stats{$key}{pass} ||0, $stats{$key}{fail} ||0, $stats{$key}{new_a} ||0, scalar keys %{ $stats{$key}{user} }, $module; } __DATA__ 05/Jun/2003:00:01:23 user1 agency1 url1 garbage pass mod1 more_garbage 05/Jun/2003:00:03:17 user2 null url1 garbage fail mod1 more_garbage 05/Jun/2003:00:03:42 user1 agency1 url1 garbage pass mod1 more_garbage 05/Jun/2003:00:05:03 user6 agency2 url1 garbage pass mod1 more_garbage 05/Jun/2003:00:08:34 user3 agency2 url1 garbage pass mod1 more_garbage 05/Jun/2003:00:11:59 user4 agency2 url2 garbage fail mod1 more_garbage 05/Jun/2003:00:14:30 user5 agency2 url1 garbage new_a mod1 more_garbag +e 05/Jun/2003:00:15:02 user1 agency1 url1 garbage pass mod1 more_garbage 05/Jun/2003:00:16:56 user7 agency2 url2 garbage pass mod2 more_garbage 05/Jun/2003:00:17:31 user1 agency1 url1 garbage fail mod1 more_garbage 05/Jun/2003:00:17:31 user1 agency1 url1 garbage pass mod2 more_garbage
output
D:\Perl\test>test agency1 url1 3 1 0 1 mod1 agency1 url1 1 0 0 1 mod2 agency2 url1 2 0 1 3 mod1 agency2 url2 0 1 0 1 mod1 agency2 url2 1 0 0 1 mod2 null url1 0 1 0 1 mod1
ps. Please use meaningful variable names. Your table at the top of your post showing what each field was in the input records would have been unnecessary if your code used these names instead of $e1 $e2 etc.
In reply to Re: nested hashes or object oriented
by BrowserUk
in thread nested hashes or object oriented
by ctaustin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |