Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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:
binmode FILEHANDLE, LAYER
binmode FILEHANDLE

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2014-09-02 06:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (20 votes), past polls