Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Checksum on Multidimentional Array - how does it work

by monkey_boy (Priest)
on Mar 26, 2015 at 12:04 UTC ( #1121383=note: print w/replies, xml ) Need Help??


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!!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1121383]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2021-06-23 20:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (122 votes). Check out past polls.

    Notices?