in reply to md5 sum different on windows and unix for win.exe files !!?

While you are binmoding the ftp transfer it doesnt look like you are binmoding the file you read in. On Win2 this means that first ^Z encountered in the file ends the file, it also means that perl performs CRLF type conversions before the data is seen by your code. This of course means the MD5 code on both platforms are actually looking at different data. (Printing out the length of the data read would have shown this immediately.) The answer of course is that if you are interested in byte level contents of a file (which you are) then you MUST binmode the file first irrespective of the OS.

Note that the common folk-story about not needing to binmode files on unix is not correct in the modern days of utf8 and wide characters. If you need the raw contents of a file you should binmode it regardless of operating system as the encoding could change etc.

With binmode

D:\>perl -le "use Digest::MD5 ('md5_base64'); local $/; open my $fh,sh +ift or die $!; binmode $fh if shift; $file=<$fh>; print qq(Bytes: ),l +ength($file),qq( ),md5_base64($file); " E:\Perl\bin\perl.exe 1 Bytes: 20540 vzpQPjhNDRjGpJccEa4iMw

Without binmode

D:\>perl -le "use Digest::MD5 ('md5_base64'); local $/; open my $fh,sh +ift or die $!; binmode $fh if shift; $file=<$fh>; print qq(Bytes: ),l +ength($file),qq( ),md5_base64($file); " E:\Perl\bin\perl.exe Bytes: 8295 ZFaA5qHXAClj0d1czg6hQA

PS: i surmise that the gzip files have some logic built in that makes them avoid special characters like ^Z and \0 and CRLF to avoid this type of issue in the first place. I have no idea if this is correct.

---
demerphq

Replies are listed 'Best First'.
Re^2: md5 sum different on windows and unix for win.exe files !!?
by Random_Walk (Prior) on Apr 06, 2005 at 15:40 UTC

    dmerphq++

    Thank you so much, that was just what was needed ...

    # 'doze perl -e "use Digest::MD5('md5_base64');local $/;open $f,'perl.exe'; bi +nmode $f; $dat=<$f>;print md5_base64($dat)" +QpV/tbZNRzK5aIPqc18tQ # *nix perl -le'use Digest::MD5 ("md5_base64"); local $/;open $f, "perl.exe"; + binmode $f; $dat=<$f>;print md5_base64($dat);' perl.exe +QpV/tbZNRzK5aIPqc18tQ # and the reason I was being lazy and using md5_base64(<FH>) perl -le'use Digest::MD5 ("md5_base64"); @array=qw(a b c); print md5_b +ase64(@array);' kAFQmDzST7DWlj99KOF/cg perl -le'use Digest::MD5 ("md5_base64"); @array=qw(a b c); $array=join + "",@array; print md5_base64($array);' kAFQmDzST7DWlj99KOF/cg # thought that worked, but then did this... perl -le'use Digest::MD5 ("md5_base64"); local $/;open $f, "perl.exe"; + $data=<$f>;print md5_base64($data);' perl.exe +QpV/tbZNRzK5aIPqc18tQ perl -le'use Digest::MD5 ("md5_base64"); local $/;open $f, "perl.exe"; + binmode $f; print md5_base64($f);' perl.exe MzTg3hOPoYjcGlfa8CHjeg

    Cheers,
    R.

    Pereant, qui ante nos nostra dixerunt!

      You can do that a little more easily:

      perl -MDigest::MD5=md5_base64 -0777 -e"binmode STDIN; print md5_base64 + <STDIN>" <\bin\perl.exe

      Note: The '<' before the filename which may get obscured by the wrap.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco.
      Rule 1 has a caveat! -- Who broke the cabal?