Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: counting pairwise incidences

by jpl (Monk)
on May 17, 2011 at 14:19 UTC ( #905277=note: print w/ replies, xml ) Need Help??


in reply to counting pairwise incidences

Or, as a minor variant of the code posted by moritz

use strict; use warnings; my %pairs; while (<DATA>) { my @names = split; # my @names = sort split; # if order shouldn't matter while ( @names > 1 ) { my $first = shift(@names); map { ++$pairs{ join '_', $first, $_ } } @names; } } while ( my ( $k, $v ) = each %pairs ) { print "$k: $v\n"; } __DATA__ tomD gly4 phil aesG tomD gly4 phil aesG phil aesG tomD gly4


Comment on Re: counting pairwise incidences
Download Code
Re^2: counting pairwise incidences
by reubs85 (Acolyte) on May 19, 2011 at 13:33 UTC

    Thanks everyone for their help! The order doesn't matter so the variant of the code supplied by moritz and jpl works a treat. Highly impressed by the speed of answering btw; I just checked back on the site I never expected replies to be so quick... long live the brotherhood!

    Cheers!

    Reuben

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://905277]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-07-25 06:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (169 votes), past polls