sub file2sha1 {
my $file=$_[0];
return '' if -d $file; #have to find out if to prune when a directory is found that doesn't match the regex
open my $f,"<$file";
my $sha1 = Digest::SHA1->new;
$sha1->addfile(*$f);
return $sha1->hexdigest;
}
- You should open the file in "binary" mode to work correctly.
- You should verify that the file opened correctly.
- *$f makes no sense because $f is a lexical variable that contains a reference to a filehandle.
- You should probably use $sha1->digest instead which is half the size of $sha1->hexdigest.
sub file2sha1 {
my $file = $_[ 0 ];
return '' if -d $file; #have to find out if to prune when a direct
+ory is found that doesn't match the regex
open my $f, '<:raw', $file or do {
warn "Cannot open '$file' $!";
return;
};
my $sha1 = Digest::SHA1->new;
$sha1->addfile( $f );
return $sha1->digest;
}