aboutsummaryrefslogtreecommitdiff
path: root/challenge-047
diff options
context:
space:
mode:
authorDuane Powell <duane.r.powell@gmail.com>2020-02-11 08:09:42 -0600
committerDuane Powell <duane.r.powell@gmail.com>2020-02-11 08:09:42 -0600
commit89bae6347f09236b2298383a2898d55887c10b75 (patch)
treec1d45692f87b8ba65809d493c3209ea9adfaecb5 /challenge-047
parent69ad278fc8ffbe6e311317ee02d98c09ff332a12 (diff)
downloadperlweeklychallenge-club-89bae6347f09236b2298383a2898d55887c10b75.tar.gz
perlweeklychallenge-club-89bae6347f09236b2298383a2898d55887c10b75.tar.bz2
perlweeklychallenge-club-89bae6347f09236b2298383a2898d55887c10b75.zip
Clean up sloppy control logic
Diffstat (limited to 'challenge-047')
-rwxr-xr-xchallenge-047/duane-powell/perl5/ch-1.pl17
1 files 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 {