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.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller



In reply to Re: nested hashes or object oriented by BrowserUk
in thread nested hashes or object oriented by ctaustin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.