Miguel has asked for the wisdom of the Perl Monks concerning the following question:
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:
*** UPDATE ***my @A0A3 = ( [2003,2],[2003,5],[2003,6],[2003,7],[2003,8], [2003,9],[2003,10],[2003,11],[2003,12],[2004,2] );
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I compare 2 Arrays of Arrays and get a 3rd one?
by BrowserUk (Patriarch) on Apr 02, 2004 at 01:04 UTC | |
|
Re: How do I compare 2 Arrays of Arrays and get a 3rd one?
by davido (Cardinal) on Apr 02, 2004 at 01:05 UTC | |
|
Re: How do I compare 2 Arrays of Arrays and get a 3rd one?
by DamnDirtyApe (Curate) on Apr 02, 2004 at 02:05 UTC | |
by greenFox (Vicar) on Apr 02, 2004 at 09:02 UTC | |
|
Re: How do I compare 2 Arrays of Arrays and get a 3rd one?
by Enlil (Parson) on Apr 02, 2004 at 01:31 UTC |