Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^7: Digest::SHA gives different values for unix/windows

by zork42 (Monk)
on Jun 14, 2013 at 07:07 UTC ( #1038907=note: print w/replies, xml ) Need Help??

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.

From perlfunc.html:

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 :)
  • Comment on Re^7: Digest::SHA gives different values for unix/windows

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2018-10-17 11:21 GMT
Find Nodes?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...

    Results (92 votes). Check out past polls.