Using pseudo(hash-based)-bit-vectors, this code is somewhat easier on the eyes (IMHO):
#! perl use strict; my (%name); while (<DATA>){ my( $n, $rest ) = split; $name{$n}{$_}=1 for ( split ',', $rest ); } print "\t",map ({"$_\t"} sort keys %name),"\n"; # First line for my $n1( sort keys %name){ print "$n1:\t"; for my $n2( sort keys %name){ my $count=scalar keys %{$name{$n2}}; $name{$n2}{$_} and $count-- for keys %{$name{$n1}}; print "$count\t"; } print "\n"; } __DATA__ Name1 USA,Canada,Yemen Name2 Canada,Portugal,India Name3 China,HongKong,Canada Name4 London,Amsterdam,Ireland,USA Name5 India,USA,Canada
My results seem transposed because of a different approach to counting.

             All great truths begin as blasphemies.
                   ― George Bernard Shaw, writer, Nobel laureate (1856-1950)


In reply to Re: Doing pair-exclusivity analysis and building a matrix by NetWallah
in thread Doing pair-exclusivity analysis and building a matrix by angerusso

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.