#!/usr/bin/perl -w use strict; $|++; my %source; my %action; my %sub_action; ## # process file while () { my ($source, $action, $sub_action) = split; my $source_action = $source . "||" . $action; # sub_action isn't required to appear my $source_sub_action = $source_action . "||" . $sub_action if $sub_action; $source{$source}++; $action{$source_action}++; # sub_action isn't required to appear $sub_action{$source_sub_action}++ if $source_sub_action; } ## # print statistics while (my ($source_code, $source_code_count) = each %source) { print "source code: $source_code count: $source_code_count\n"; # print actions and counts for this source code foreach my $action (keys %action) { print "action: $action count: $action{$action}\n" if $action =~ /$source_code\|\|/; } # print sub_actions and counts for this source code foreach my $sub_action (keys %sub_action) { print "sub action: $sub_action count: $sub_action{$sub_action}\n" if $sub_action =~ /$source_code\|\|/; } } __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 #### # build datastructures while (logfile) { build hash1; build hash2; build hash3; } # process the datastructures foreach key value (hash1) { foreach over keys of hash2; foreach over keys of hash3; }