boboman has asked for the wisdom of the Perl Monks concerning the following question:

perl -MDigest::SHA=sha256_hex -le "print sha256_hex <>" <path to filename> returns the same SHA 256 value as the UNIX command shasum -a 256 <path to filename>. However, when the Digest::SHA module is called from within a perl script the output value is different $file = /path to filename; print sha256_hex("$file"); The print command should return the same value but I cannot work out a method to do this.

Replies are listed 'Best First'.
Re: sha256_hex checksum problem
by haukex (Archbishop) on Sep 04, 2019 at 10:24 UTC

    sha256_hex takes the data to be checksummed, not a filename, so what you're seeing is the SHA-256 checksum of the filename.

    Try this instead: print Digest::SHA->new("SHA-256")->addfile($filename)->hexdigest;

      That works great. Thanks.