The following appears to do the trick. I've just dumped the results with Data::Dumper, so it's up to you to figure out who you want to format them.

#!/usr/bin/perl -w use strict; $|++; my %source; # process file while (<DATA>) { my ($source, $action, $sub_action) = split; my $source_action = $source . "||" . $action; # sub_action isn't required to appear $source{ $source }{ count }++; $source{ $source }{ $action }{ count }++; $source{ $source }{ $action }{ $sub_action }{ count }++ if $sub_acti +on; } use Data::Dumper; print Dumper \%source; __DATA__ source1 QUEUED source1 QUEUED source1 CLICK linkid1 source1 CLICK linkid1 source1 CLICK linkid2 source2 QUEUED source2 CLICK linkid1 source2 CLICK linkid1 source2 CLICK linkid2

Cheers,
Ovid

Update: If Data::Dumper output bugs you, here's a quick hack at printing the results.

foreach my $source ( sort keys %source ) { print "$source\n\tcount: $source{$source}{count}\n"; foreach my $action ( sort keys %{$source{$source}} ) { next if $action eq 'count'; print "\t$action\n\t\tcount: $source{$source}{$action}{count}\n"; foreach my $sub_action (sort keys %{$source{$source}{$action}} ) { next if $sub_action eq 'count'; print "\t\t$sub_action\n\t\t\tcount: $source{$source}{$action}{$ +sub_action}{count}\n"; } } }

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to Re: Choosing the right datastructure by Ovid
in thread Choosing the right datastructure by dug

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.