http://www.perlmonks.org?node_id=1088407


in reply to Count number of elements in HoH and sum them for other keys

A simple hash is all you need. Use the things you want to count as keys.
use strict; use warnings; my %hash; while (<DATA>) { my @elements = split; $hash{join ' => ', @elements[0,1]}++; $hash{$elements[0]}++; } foreach my $key (sort keys %hash) { printf "%-6s => %d\n", $key, $hash{$key}; } __DATA__ A B n1 A B n2 A C n1 D E n2 D E n4 D F n1
OUTPUT:
A => 3 A => B => 2 A => C => 1 D => 3 D => E => 2 D => F => 1
Bill