http://www.perlmonks.org?node_id=1121383


in reply to Checksum on Multidimentional Array - how does it work

my $ref_array1 = @array1; my $ref_array2 = @array2; my $str = md5($ref_array1); my $str2 = md5($ref_array2);
You are doing a digest both times on the count of the items in the arrays, i.e:
print $ref_array1; print $ref_array2;
outputs:
5
5


Even if you actually took a reference to to these arrays, (my $ref_array1 = \@array1;) your solution would never work, as you would be digesting just a memory code/id for the two named arrays.
The solution here is I suspect, to serialize the arrays & digest the stringified values, e.g:
#!/usr/bin/env perl use Modern::Perl; use Data::Dumper; use Digest::MD5 qw(md5 md5_hex md5_base64); my @array1 = ( [1,'John','ABXC12132328'], [0,'John','ABXC12132322'], [0,'John','ABXC12132322'], [0,'John','ABXC12132322'], [0,'John','ABXC12132322'] ); my @array2 = ( [0,'John','ABXC12132322'], [0,'John','ABXC12132322'], [0,'John','ABXC12132322'], [0,'John','ABXC12132322'], [0,'John','ABXC12132322'] ); my @array3 = @array2; #print Dumper(\@array1); my $md5_1 = md5_hex(Dumper(\@array1)); my $md5_2 = md5_hex(Dumper(\@array2)); my $md5_3 = md5_hex(Dumper(\@array3)); say 1,' ',$md5_1; say 2,' ',$md5_2; say 3,' ',$md5_3;


This is not a Signature...

Replies are listed 'Best First'.
Re^2: Checksum on Multidimentional Array - how does it work
by udvk009 (Novice) on Mar 26, 2015 at 14:07 UTC

    Thanks folks for the quick reply and explaining the implementation ! Appreciate the help ... cheers!!