Hello monks, I know what I need to do, but just am not quite sure how to do it. The below code works, but can become very slow for large sets of data. Basically, the problem is, I can have multiple sets of data, and want to compare between all sets, but not within the set itself. An example will lend a hand in my poor explanation:
@array = ([1,2,3],[5,5,6],[1,4,6]);
In this case, I would like to pick out 1 and 6 as duplicates through the sets of data. However, 5 is not a duplicate, because I don't care about the duplicates within a set. I think the fastest way to do this is probably using the exists function with hashes, but I'm not quite sure how to do it effeciently. My sad attempt at doing this(coming from a C background) is shown below. Like I said, it works, but it's very time consuming due to the nested loops. Thanks in advance to all help!
my $loop_index = 0; for $comma_array (@current_case_commas) { for my $comma (@$comma_array) { if($comma != "") { for (my $i=0; $i < $loop_index; $i++) { my @other_cases_array = @{$current_case_commas[$i]}; for my $other_cases (@other_cases_array) { if($other_cases = "") { if ($comma == $other_cases) { $final_case_values_duplicate{$comma} = +(); } } } } for (my $i=$loop_index+1; $i <= $#current_case_commas; +$i++) { my @other_cases_array = @{$current_case_commas[$i]}; for my $other_cases (@other_cases_array) { if($other_cases != "") { if ($comma == $other_cases) { $final_case_values_duplicate{$comma} = +(); } } } } } } $loop_index+=1; }
Oh, and one more thing now that I see the code. The lines where I have to check for a null or space in the array. I am not quite sure how they got there, and would like to get rid of them all together. The way I enter things into the array is:
push @array, split(/[\s|\t]+/,$list_of_num);
Where the list is a space separated list of numbers. I am not sure why(since I'm splitting on spaces/tabs) a blank would get into the array in the first place. Thanks again for putting up with another newbie, and all your help.

In reply to 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.