in reply to Doing pair-exclusivity analysis and building a matrix
Update:
To find the common things, one way is to set up 2 translation hash tables like below - these can be used in combination to achieve that goal, but I am still unsure about "what difference means".
#!/usr/bin/perl -w use strict; use Data::Dump qw(pp); my %country_2_name; my %name_2_country; while (<DATA>) { s/\s*$//; # trim trailing spaces (also chomps) my ($name, $countries) = split(' ',$_,2); my @these_countries = split(/,/,$countries); $name_2_country{$name} = [@these_countries]; foreach my $this_country (@these_countries) { push @{$country_2_name{$this_country}}, $name; } } pp \%country_2_name; pp \%name_2_country; =prints { Amsterdam => ["Name4"], Canada => ["Name1", "Name2", "Name3", "Name5"], China => ["Name3"], HongKong => ["Name3"], India => ["Name2", "Name5"], Ireland => ["Name4"], London => ["Name4"], Portugal => ["Name2"], USA => ["Name1", "Name4", "Name5"], Yemen => ["Name1"], } { Name1 => ["USA", "Canada", "Yemen"], Name2 => ["Canada", "Portugal", "India"], Name3 => ["China", "HongKong", "Canada"], Name4 => ["London", "Amsterdam", "Ireland", "USA"], Name5 => ["India", "USA", "Canada"], } =cut __DATA__ Name1 USA,Canada,Yemen Name2 Canada,Portugal,India Name3 China,HongKong,Canada Name4 London,Amsterdam,Ireland,USA Name5 India,USA,Canada
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Doing pair-exclusivity analysis and building a matrix
by angerusso (Novice) on Mar 28, 2012 at 02:47 UTC |