in reply to counting pairwise incidences
I'm not sure if I understood what pairs you want counted. If a line has the entries a, b, c, d, do you want the pairs ab, ac, ad, bc, bd, cd?
If yes, this code should do what you want:
use strict; use warnings; my %pairs; while (<DATA>) { my @names = split; for my $first (0..$#names - 1) { for my $second ($first + 1 .. $#names) { my $p = join '_', @names[$first, $second]; $pairs{$p}++; } } } while (my ($k, $v) = each %pairs) { print "$k: $v\n"; } __DATA__ tomD gly4 phil aesG tomD gly4 phil aesG phil aesG tomD gly4
If not, you need to explain what pairs you want to count.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: counting pairwise incidences
by ikegami (Patriarch) on May 17, 2011 at 17:26 UTC | |
|
Re^2: counting pairwise incidences
by LanX (Saint) on May 17, 2011 at 14:52 UTC |