in reply to
Re^6: Digest::SHA gives different values for unix/windows
in thread Digest::SHA gives different values for unix/windows
Hi Jim, thanks for the welcome!
"By default, $filename is simply opened and read; no special modes or I/O disciplines are used."
I agree this is not very clear.
My interpretation was that Digest::SHA::addfile() will default to text mode, at least it would under Windows. With Windows you must explicitly select binmode or open filehandles default to text mode.
binmode FILEHANDLE, LAYER
Arranges for FILEHANDLE to be read or written in "binary" or "text" mode on systems where the run-time libraries distinguish between binary and text files. If FILEHANDLE is an expression, the value is taken as the name of the filehandle. Returns true on success, otherwise it returns undef and sets $! (errno).
On some systems (in general, DOS and Windows-based systems) binmode() is necessary when you're not working with a text file. For the sake of portability it is a good idea to always use it when appropriate, and to never use it when it isn't appropriate. Also, people can set their I/O to be by default UTF-8 encoded Unicode, not bytes.
In other words: regardless of platform, use binmode() on binary data, like for example images.
Anyway, I think if I use Digest::SHA::addfile() in the future I'll RTFSC first :)