swampyankee is correct. Here is some code that shows the principle:
use strict;
use warnings;
use Data::Dumper;
use Digest::MD5 qw(md5);
my %lookup;
my @AoA =
(
["a", "b", "c"],
["d", "e", "f"],
["a", "b", "c"],
["g", "h", "i"],
["a", "b", "c"],
["g", "h", "i"],
);
#Build a lookup hash from AoA, values of the hash will be
#an arrayref to the positions where a given array was found
my $index = 0;
for ( @AoA )
{
my $k = md5(Dumper($_));
push @{$lookup{$k}}, $index++;
}
$index = 0;
#test data
my @test =
(
["a", "b", "c"],
["d", "e", "f"],
["g", "h", "i"],
["x", "y", "z"],
);
#loop tests
for ( @test )
{
print "Test ", $index++, ": ", join (", ", @{ref_exists($_)}), "\n
+";
}
#returns the positions or undef when the arrayref is not in AoA
sub ref_exists
{
return $lookup{md5(Dumper(shift))} || [];
}
Note that, because I use Data::Dumper for creating the digest, the technique should work for deep structures also, not just for plain arrays of strings.
|