in reply to Choosing the right datastructure
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Choosing the right datastructure
by dug (Chaplain) on Apr 07, 2002 at 04:04 UTC |