in reply to matching large arrays then updating

From the sounds of it, you have two AoAs like the following:

my @array1 = ( [ id1, ... 169 other fields ... ], [ id2, ... 169 other fields ... ], ... ~200k other records ... ); my @array2 = ( [ id2, ... 169 other fields ... ], [ id5, ... 169 other fields ... ], ... ~50k other records ... );

Start by making it easy to find records in array2.

my %array2 = map { $_->[0] => $_ } @array2;

Then the problem becomes trivial.

for my $array1_rec (@array1) { my $array2_rec = $array2{ $array1_rec->[0] } or next; ... Change @$array1_rec based on values from @$array2_rec ... }

You don't actually need to create @array1 or @array2.

Replies are listed 'Best First'.
Re^2: matching large arrays then updating
by devan999 (Initiate) on Oct 21, 2011 at 19:00 UTC
    -ikegami You illustrated my problem perfectly and the solution I was looking for! Thanks for the help!
Re^2: matching large arrays then updating
by devan999 (Initiate) on Oct 24, 2011 at 16:44 UTC
    -ikegami I've followed your logic but I'm having the following issue:
    my %array2 = map { $_->[0] => $_ } @array2;
    produces the following problem:
    The %array2 contains a single line: key="" and %array{$key} returns one record from array2

    The initial array from the file contains 200k records but they are not being added to the hash...
    I've tried many ways to map the array but I've been unsuccessful so far...
    Thanks again for you help.

      The initial array from the file contains 200k records but they are not being added to the hash...

      Then your data isn't arranged as you said it is.

      The %array2 contains a single line: key=""

      Hashes have elements, not lines.

      and %array{$key} returns one record from array2

      %array{$key} is a syntax error, there is no variable named "%array" in this discussion, and "array2" could refer to the array @array2 or the hash %array2.

      The initial array from the file contains 200k records but they are not being added to the hash...

      My code doesn't even try to add the 200k records of @array1 to the hash. It adds the 50k records of @array2.