From 647ff4046a7d012bc4cf583bfcd72b4e09265418 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 29 Jun 2018 19:53:22 +1200 Subject: Refactor digest alg selection --- checkem | 26 +++++++++++--------------- 1 file 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; -- cgit v1.2.3