Greetings to all Monks,

I've been seraching for some help on how to compare and extract the differences between 2 Arrays of Arrays, but I'm totally lost in here.

My problem is:

I have 2 @AoA

my @A0A1 = ( [2003,1],[2003,3],[2003,4],[2004,1] ); my @A0A2 = ( [2003,1],[2003,2],[2003,3],[2003,4],[2003,5],[2003,6], [2003,7],[2003,8],[2003,9],[2003,10],[2003,11],[2003,12], [2004,1],[2004,2] );

Any help on how to compare these @A0As and get a 3rd one filled with the differences?
In this case would be something like this:

my @A0A3 = ( [2003,2],[2003,5],[2003,6],[2003,7],[2003,8], [2003,9],[2003,10],[2003,11],[2003,12],[2004,2] );
*** UPDATE ***

Esteemed Monks, thank you very much for your help.

Now, as I look and try your code, I'm asking myself if my problem could be solved in another way.

This is, the @AoA1 is always a subset of @A0A2, and values come from DB.

The @A0A2 values are calculated like this:

my $start_year = 2003; my $actual_year = 2004; my $actual_month = 3; while ( $start_year <= $actual_year ) { foreach ( my $i=1;$i<13;$i++ ) { if (( $actual_month > $i ) && ( $start_year == $actual_year )) { push @A0A2, [$start_year,$i]; } elsif ( $start_year != $actual_year ) { push @A0A2, [$start_year,$i]; } } $start_year++; }

This way i have a @A0A2 filled with Years and Months until a given month and a given year.

My question is: would be better to push and eliminate those values that exists on both @A0As while I'm _building_ the @A0A2? If so, how should I do that?

Thanks again for your patience.


In reply to How do I compare 2 Arrays of Arrays and get a 3rd one? - updated - by Miguel

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.