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


in reply to counting pairwise incidences

The challenge is only to iterate all the 2-member subsets of the set on a per line basis. For example:
use Data::Dumper; my %pairs = (); while (<>) { chomp; my @found = split; for my $k1 ( @found ); for my $k2 ( @found ) { if ( $k2 gt $k1 ) { # ensuring each pair is counted once o +nly for the line $pairs{ $k1 }{ $k2 }++; } } } } print Dumper \%pairs;
(updated thanks to syntax catch by Wind)

One world, one people