diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-06-29 19:53:22 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-06-29 19:54:42 +1200 |
commit | 647ff4046a7d012bc4cf583bfcd72b4e09265418 (patch) | |
tree | 02af2aad19b5c9b805ea6480fcff66b27c95e510 | |
parent | Use interpolated error string (diff) | |
download | checkem-develop.tar.gz checkem-develop.zip |
Refactor digest alg selectiondevelop
-rwxr-xr-x | checkem | 26 |
1 files changed, 11 insertions, 15 deletions
@@ -40,23 +40,19 @@ my %STATS = ( size => 7, ); -# We need to pick and create a Digest object -my $dig; - -# We were told which algorithm to use -if ( exists $ENV{CHECKEM_ALG} ) { - $dig = Digest->new( $ENV{CHECKEM_ALG} ); -} +# Use either the specified algorithm or a default list +my @algs = + exists $ENV{CHECKEM_ALG} + ? $ENV{CHECKEM_ALG} + : qw(SHA-256 SHA-1 MD5); -# Try worse and worse algorithms until we get a digest object -else { - for my $alg (qw(SHA-256 SHA-1 MD5)) { - last if eval { $dig = Digest->new($alg) }; - } +# Build digest object or give up +my $dig; +for (@algs) { + last if eval { $dig = Digest->new($_) }; } - -# Still no digest object, give up -defined $dig or die "Could not create a useable Digest object\n"; +defined $dig + or die "Could not create a useable Digest object\n"; # Start a hash of filesizes to file names/stats... my %sizes; |