Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: counting pairwise incidences

by SimonClinch (Deacon)
on May 17, 2011 at 14:20 UTC ( #905278=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://905278]
help
Chatterbox?
[stevieb]: Corion: the problem with that is the 2.36 represents the underlying C library I've wrapped, which is why I want to use incrementals after the real version number. I've emailed modules@ to see if they can expedite the process for me...
[stevieb]: ...as normally, it takes three days to delete, in case you want to change your mind

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (11)
As of 2017-01-19 15:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (170 votes). Check out past polls.