diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-08-10 01:27:35 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-08-10 01:32:29 +1200 |
commit | 28d86dd570327d5bd0ee8ee88a5c140c70ef8e28 (patch) | |
tree | f49698fb0c973f9e590013a469c5837450005cfa | |
parent | Use generic Digest module frontend (diff) | |
download | checkem-28d86dd570327d5bd0ee8ee88a5c140c70ef8e28.tar.gz (sig) checkem-28d86dd570327d5bd0ee8ee88a5c140c70ef8e28.zip |
Perl 5.6 compatible syntaxv2.9
Only a few tweaks required and we don't lose any functionality except
the lazy-loading of the Digest object, which is probably overkill anyway
-rwxr-xr-x | checkem | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -25,12 +25,11 @@ use File::Find; use Digest; # Version number to make Perl::Critic happy -our $VERSION = 2.8; +our $VERSION = 2.9; # If no arguments, work with the current working directory if ( !@ARGV ) { - say {*STDERR} 'Need at least one dir to search' - or carp 'Failed stderr write'; + printf {*STDERR} "%s\n", 'Need at least one dir to search'; exit 2; } @@ -43,9 +42,13 @@ my %STATS = ( size => 7, ); -# Figure out the Digest algorithm to use; defaults to SHA-256, but can be -# overriden by setting CHECKEM_ALG in the environment -my $alg = $ENV{CHECKEM_ALG} // 'SHA-256'; +# Create a digest object; defaults to SHA-256, but can be overriden by setting +# CHECKEM_ALG in the environment +my $dig = Digest->new( + exists $ENV{CHECKEM_ALG} + ? $ENV{CHECKEM_ALG} + : 'SHA-256', +); # Start a hash of filesizes to file names/stats... my %sizes; @@ -78,7 +81,7 @@ find { # If there's more than one filename of any of the sizes, look for hard links, # checksum them if not linked, and push them into a sums table -my ( %sums, $dig ); +my %sums; for my $fs ( grep { @{$_} > 1 } values %sizes ) { # Keep a temporary table of inodes to catch hard links @@ -99,7 +102,7 @@ for my $fs ( grep { @{$_} > 1 } values %sizes ) { open my $fh, '<', $f->{name} or croak 'Failed to open file'; binmode $fh; - ( $dig //= Digest->new($alg) )->addfile($fh); + $dig->addfile($fh); close $fh or croak 'Failed to close file'; push @{ $sums{ $dig->digest() } }, $f; |