In one of the cases you forgot the *

Interestingly, I don't get any difference in SHA1 (with or without the * — though the latter doesn't work with strictures of course, i.e. it gives Bareword "IN" not allowed while "strict subs" in use).

#!/usr/bin/perl -l #use strict; use warnings; use Digest::SHA1; my $fname = $ARGV[0]; my $sha1; open(IN, $fname) || die "can't open '$fname' for input: $!"; binmode IN; $sha1 = Digest::SHA1->new; $sha1->addfile(IN); print $sha1->hexdigest; open(IN, $fname) || die "can't open '$fname' for input: $!"; binmode IN; $sha1 = Digest::SHA1->new; $sha1->addfile(*IN); print $sha1->hexdigest; open(my $fhIN, $fname) || die "can't open '$fname' for input: $!"; binmode $fhIN; $sha1 = Digest::SHA1->new; $sha1->addfile($fhIN); print $sha1->hexdigest; system 'sha1sum', $fname;

Output for a file "foo" containing "bar\n":

$ ./840698.pl foo e242ed3bffccdf271b7fbaf34ed72d089537b42f e242ed3bffccdf271b7fbaf34ed72d089537b42f e242ed3bffccdf271b7fbaf34ed72d089537b42f e242ed3bffccdf271b7fbaf34ed72d089537b42f foo

Anyhow, to avoid the confusion, the OP could've used a lexical file handle, as shown in the third variant above.


In reply to Re^2: Digest::Sha1 differences by almut
in thread Digest::Sha1 differences by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.