The way I understand your logic, the following code should work even for the cases like
Pass Fail New
p1   
-     p1 
p1
p1
p2
-     p3
-     -    p4
Your Unique will be 3 in this case. (for p1,p2,p4).

I have assumed that for the output table, your primary key consists of agency, url and module as figured out from the results.

use strict; use warnings; use Data::Dumper; my $hash; while(<DATA>){ chomp; my @fields = split /\s+/; my ($agency,$url,$mod) = @fields[2,3,6]; my ($user,$state) = @fields[1,5]; my $item = $hash->{$agency}{$url}{$mod}; if($state eq 'pass'){ $hash->{$agency}{$url}{$mod}{pass} += 1; }elsif($state eq 'fail'){ $hash->{$agency}{$url}{$mod}{fail} += 1; } elsif($state =~ /new_/){ $hash->{$agency}{$url}{$mod}{new} += 1; } $hash->{$agency}{$url}{$mod}{users}{$user} += 1 if $state ne 'fail +'; } print join "\t" => qw(Agency URL Pass Fail New Unique Module),"\n"; foreach my $agency (keys %{$hash}){ foreach my $url (keys %{$hash->{$agency}}){ foreach my $mod (keys %{$hash->{$agency}{$url}}){ my $item = $hash->{$agency}{$url}{$mod}; my $pass = $item->{pass} || 0; my $fail =$item->{fail} || 0; my $new = $item->{new} || 0; my $unique =scalar keys %{$item->{users}}; print join "\t" => ($agency,$url,$pass,$fail,$new,$unique,$mod +),"\n"; } } } __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 agnecy2 url1 garbage pass mod1 more_garbage 05/Jun/2003:00:08:34 user3 agnecy2 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 agnecy2 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
Agency	URL	Pass	Fail	New	Unique	Module	
null	url1	0	1	0	0	mod1	
agency1	url1	3	1	0	1	mod1	
agency1	url1	1	0	0	1	mod2	
agency2	url2	0	1	0	0	mod1	
agency2	url2	1	0	0	1	mod2	
agnecy2	url1	2	0	1	3	mod1
artist

In reply to Re: nested hashes or object oriented by artist
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.