Not sure exactly what you're trying to do here, but I've assumed that you want an output of 3 values for each array, the first two being the most unique two values and equal uniqueness being decided by array position, and the third being the first value common to all arrays. I know this doesn't yield the same output as what you have, but I wasn't sure what you wanted:
use strict; use warnings; my (@sets, $n, %c, @u, @a); while (<DATA>) { chomp; push @sets, [split /,/]; } for (@sets) { $c{$_}++ for (@$_); } $n = $#sets + 1; for (@sets) { print '[' . join(',', @$_) . '] = ['; @u = (); @a = (); for (@$_) { if ($c{$_} != $n) { push(@u, [$_, $c{$_}]); } else { push (@a, $_); } } for ((sort {@$a[1] cmp @$b[1]} @u)[0..1]) { print @$_[0] . ','; } print $a[0] . "]\n"; } __DATA__ 1,2,3,4,5,6 3,4,5,7,8 3,6,8,9
The key is the counts:
for (@sets) { $c{$_}++ for (@$_); }
This gives you the total number of times each value is used over the entire nested array. If the number is equal to the number of arrays, then the value is common to all arrays; if the number is 1, then the value is unique to whichever array contains it. Numbers in between can be used to fill in if there aren't enough 1's, as shown above.

I've assumed that there are always at least two values in each array not common to all arrays. I've also assumed that the arrays can contain non-numerical values, which is why I'm using cmp for the sort instead of <=>.


In reply to Re: Mutually Exclusive Elements by TedPride
in thread Mutually Exclusive Elements by Anonymous Monk

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.