Dear Perl experts,

Seeking advice here. I am a newbie with Perl and looking for input on the quickest way to perform a difference between two arrays.

The two arrays are going to be large, they could be holding between 6,000 to 8,000 elements, these elements will hold unique data. Due to the size of these arrays, the diff will need to be fast and not intensive on the CPU.

Here is the code I have used which does carry out its function correctly which is to find the items in @arr_1 that are not present in @arr_2.

The data in each of the arrays is unique and is an INT data type

My question is whether there is a faster way that is less intensive on the CPU?

  

    my %diff3;         @diff3{ @arr_1 } = @arr_1;     delete @diff3{  @arr_2};     @diff = (keys %diff3);

Thank you in advance, once I get up to speed on Perl, I am looking forward to paying it back.

AJ

In reply to Best method to diff very large array efficiently by newbieperlperson

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.