From 89bae6347f09236b2298383a2898d55887c10b75 Mon Sep 17 00:00:00 2001 From: Duane Powell Date: Tue, 11 Feb 2020 08:09:42 -0600 Subject: Clean up sloppy control logic --- challenge-047/duane-powell/perl5/ch-1.pl | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/challenge-047/duane-powell/perl5/ch-1.pl b/challenge-047/duane-powell/perl5/ch-1.pl index 021ee1013f..d94590a8a7 100755 --- a/challenge-047/duane-powell/perl5/ch-1.pl +++ b/challenge-047/duane-powell/perl5/ch-1.pl @@ -39,10 +39,10 @@ exit; sub arabic { my @roman = split(//, uc(shift)); - return 0 unless (scalar @roman > 0); - my ($arabic, $next, $error, $min) = (0, '', '', 1000); - while (1) { + + while (scalar @roman and not $error) { + # Check for matching pair of Roman numerals, eg 'IV' if (scalar @roman > 1) { $next = $roman[0].$roman[1]; if ( defined($arabic{$next}) ) { @@ -54,6 +54,7 @@ sub arabic { next; } } + # Pair not found, maybe there is one matching numeral, eg 'I' if (scalar @roman > 0) { $next = $roman[0]; if ( defined($arabic{$next}) ) { @@ -67,19 +68,13 @@ sub arabic { $error = "Invalid Roman numeral at $next"; } } - else { - last; - } - - last if ($error); } + if ($error) { say $error; exit; } - else { - return $arabic; - } + return $arabic; } sub roman { -- cgit