in reply to Digest::MD5::md5_hex giving different values on different machines

To further your cause for information, it might help if you showed Perl/Digest::MD5 and md5sum producing different results. Eg. c&p the shell output.

That would show which combination is producing the wrong results.

Given sisyphus' recent problems with using integers on 64-bit platforms, one possibility is the conversion of the 128-bit integer to hex there has issues.

Another possibility is that you aren't binmodeing the file before reading it. A more common mistake on win32, but with the advent of unicode, maybe that is affecting the results?

Example: The first perl command doesn't binmode the file, the second does:

C:\test>perl -MDigest::MD5=md5_hex -wle"print md5_hex( do{local $/; <> } )" 1Mx4096.db 22502b12bc292ae0a0aa1f4a33942662 C:\test>perl -MDigest::MD5=md5_hex -wle"open I, '<:raw', $ARGV[ 0 ]; print md5_hex(do{local $/; <I>})" 1M +x4096.db 66bff1dfd44db7d4402171056d494b2d C:\test>md5sum 1Mx4096.db 66bff1dfd44db7d4402171056d494b2d *1Mx4096.db

Update: As ikegami alludes to below, in the light of Using ":raw" layer in open() vs. calling binmode(), whether it's broken documentation or a bug in PerlIO, it seems that you need '<:raw:perlio' to achieve the same as binmode via open, which is important if performance is a consideration.


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".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: Digest::MD5::md5_hex giving different values on different machines
by ikegami (Patriarch) on Jun 20, 2007 at 17:10 UTC

    You should probably be using binmode...

    In fact, that could very well be the problem is one of the machines is a Windows machine and the other one isn't.