in reply to Find number of unique values in hash
my %counts=(); foreach $kid (%hoh) { foreach my $attribute (%$kid) { $counts{$attribute}{$kid->{attribute})++; } } ... print $counts{'age'}{12};
Sadly this "one-time" cost has to be paid whenever the data changes (unless you also adjust the counts in the second HoH whenever you change anything)
UPDATE: Fixed the bug in the first line thanks to warnings from johngg and chromatic. It was too much to hope that I could write even a 4-liner without a trivial bug.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Find number of unique values in hash
by johngg (Canon) on Jan 20, 2010 at 00:04 UTC |