aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-097/abigail/perl/ch-1.pl13
1 files changed, 10 insertions, 3 deletions
diff --git a/challenge-097/abigail/perl/ch-1.pl b/challenge-097/abigail/perl/ch-1.pl
index 7558150f4d..b73991738c 100644
--- a/challenge-097/abigail/perl/ch-1.pl
+++ b/challenge-097/abigail/perl/ch-1.pl
@@ -17,16 +17,23 @@ use experimental 'lexical_subs';
# Run as: perl ch-1.pl -s SHIFT < input-file
#
+my $NR_OF_LETTERS = 26;
+my $ORD_A = ord ('A');
+
use Getopt::Long;
GetOptions 's=i' => \my $shift;
-die "-s option required" unless defined $shift;
+die "-s SHIFT option required" unless defined $shift;
-$shift %= 26;
+$shift %= $NR_OF_LETTERS;
while (<>) {
chomp;
- s/([A-Z])/my $ch = ord ($1) - $shift; $ch += 26 if $ch < 65; chr $ch/eg;
+ s {([A-Z])}
+ { my $ch = ord ($1) - $shift;
+ $ch += $NR_OF_LETTERS if $ch < $ORD_A;
+ chr $ch
+ }eg;
say;
}