aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-06-29 19:53:22 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-06-29 19:54:42 +1200
commit647ff4046a7d012bc4cf583bfcd72b4e09265418 (patch)
tree02af2aad19b5c9b805ea6480fcff66b27c95e510
parentUse interpolated error string (diff)
downloadcheckem-647ff4046a7d012bc4cf583bfcd72b4e09265418.tar.gz
checkem-647ff4046a7d012bc4cf583bfcd72b4e09265418.zip
Refactor digest alg selectiondevelop
-rwxr-xr-xcheckem26
1 files changed, 11 insertions, 15 deletions
diff --git a/checkem b/checkem
index cc03781..aeb932d 100755
--- a/checkem
+++ b/checkem
@@ -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;