Granted that others have already posted on this, but here's my take on it. :)

First, I'd do the split as "split(/\s+/,$list_of_num)". \s is 'whitespace' which includes ' ', \t (tab), \f (form feed), \r (carrage return) and, \n (newline).

If you don't need the original inner lists in the form they were read in, why not make them a hash first? this would save you a traversal of the list to make a hash of it for the uniqe-ing part.

use strict; use Data::Dumper; my @input = ("1 2 3", "5 5 6", "1 4 6" ); # outer map: take each input line # inner map: split it on white space and return it as a hash ref my @array = map { { map { $_ => 1 } split(/\s+/,$_) } } @input; print Dumper @array; my %unique; for (my $i=0; $i<=$#array; $i++) { foreach (keys %{$array[$i]}) { $unique{$_}->{'pos'}->{$i} = 1; $unique{$_}->{'count'}++; } } my @duplicates = grep { $unique{$_}->{'count'} > 1 } keys %unique; foreach (@duplicates) { print "DUP: $_ In lists: "; print join(",",keys %{$unique{$_}->{'pos'}}); print "\n"; }
This is essentially the same idea as others have posted, execpt this keeps track of which sets each duplicate was found in.

/\/\averick


In reply to Re: Comparing between multiple sets of data by maverick
in thread Comparing between multiple sets of data by flounder

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.