aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2020-02-11 14:15:13 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2020-02-11 14:15:13 +0000
commit8e5601fa2bd064997647b6533659014c722e4777 (patch)
tree0a72c7204f3fb7774cf2e9389d3aafea4f8ba645
parentd46afcab07067b78d68f5ffd8770dfccbda9b90a (diff)
parent89bae6347f09236b2298383a2898d55887c10b75 (diff)
downloadperlweeklychallenge-club-8e5601fa2bd064997647b6533659014c722e4777.tar.gz
perlweeklychallenge-club-8e5601fa2bd064997647b6533659014c722e4777.tar.bz2
perlweeklychallenge-club-8e5601fa2bd064997647b6533659014c722e4777.zip
Merge branch 'pwc47' of git://github.com/duanepowell/perlweeklychallenge-club into duanepowell-pwc47
-rwxr-xr-xchallenge-047/duane-powell/perl/ch-1.pl17
1 files changed, 6 insertions, 11 deletions
diff --git a/challenge-047/duane-powell/perl/ch-1.pl b/challenge-047/duane-powell/perl/ch-1.pl
index 021ee1013f..d94590a8a7 100755
--- a/challenge-047/duane-powell/perl/ch-1.pl
+++ b/challenge-047/duane-powell/perl/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 {