Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Checksum on Multidimentional Array - how does it work

by BrowserUk (Patriarch)
on Mar 26, 2015 at 11:55 UTC ( [id://1121382]=note: print w/replies, xml ) Need Help??


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

Because you're not checksumming the arrays. You are checksumming the lengths of the arrays (which are the same):

my $ref_array1 = @array1; ## Assigns the length of @array1 to $ref_ar +ray!!! my $ref_array2 = @array2; ## Ditto!

To checksum the contents of the arrays, one way would be to serialise them (convert to a string representation):

#!C:\Perl5.16\bin\perl.exe 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'] ); #print Dumper(\@array1); my $ref_array1 = Dumper( \@array1 ); my $ref_array2 = Dumper( \@array2 ); my $str = md5_hex($ref_array1); my $str2 = md5_hex($ref_array2); print "md-check-sum for array1 :: " . $str . "\n"; print "md-check-sum for array2 :: " . $str2 . "\n"; __END__ C:\test>1121378 md-check-sum for array1 :: b636a47153af27317478e3bca3632602 md-check-sum for array2 :: a4882627a89775602ab2e33762a70e81

Note also that I've nixed your unpack 'L', stuff which throws away 3/4 of the information in the 128-bit checksum by converting only the first 32-bits to a number.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2024-04-23 09:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found