in reply to Re: Digest::Sha1 differences
in thread Digest::Sha1 differences
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Digest::Sha1 differences
by Anonymous Monk on May 24, 2010 at 12:33 UTC |