in reply to Re: Checking if an Array is a Member of an AoA
in thread Checking if an Array is a Member of an AoA

calculate MD5 checksum of the arrayref you want to look up
Hi Holli,
Can you give example of how to do that? Is there any specific module that does this?

---
neversaint and everlastingly indebted.......
  • Comment on Re^2: Checking if an Array is a Member of an AoA

Replies are listed 'Best First'.
Re^3: Checking if an Array is a Member of an AoA
by swampyankee (Parson) on Dec 24, 2005 at 04:13 UTC

    I'm not holli's alterego, but I believe holli would point you to use Digest;, which can calculate (among others) MD5 signatures.

Re^3: Checking if an Array is a Member of an AoA
by holli (Abbot) on Dec 24, 2005 at 14:20 UTC
    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.


    holli, /regexed monk/