Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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

Replies are listed 'Best First'.
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!



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://905277]
[Corion]: We-ird - I hadn't known this, but Ingress and Pokemon Go (both AR games in the real world where you run around) switched from using Google Maps to OpenStreetMaps, which is great. But I wonder why, as Ingress is (was?) owned by Google/Alphabet. But ...
[Corion]: ... maybe not wholly owned, or the load on Google Maps was too high?!

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2018-03-19 09:06 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (236 votes). Check out past polls.