aboutsummaryrefslogtreecommitdiff
path: root/challenge-097/abigail/perl
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-01-26 01:13:15 +0100
committerAbigail <abigail@abigail.be>2021-01-26 12:07:41 +0100
commit1889deddca521e1aa013d53a749c693c6589deba (patch)
tree74ad27d14ee32de3ad6a5afdd04f895a280ddf10 /challenge-097/abigail/perl
parent6c5715542385de49f20d0f56d1c9aa66b5736cab (diff)
downloadperlweeklychallenge-club-1889deddca521e1aa013d53a749c693c6589deba.tar.gz
perlweeklychallenge-club-1889deddca521e1aa013d53a749c693c6589deba.tar.bz2
perlweeklychallenge-club-1889deddca521e1aa013d53a749c693c6589deba.zip
Use an option to determine the shift size.
Diffstat (limited to 'challenge-097/abigail/perl')
-rw-r--r--challenge-097/abigail/perl/ch-1.pl16
1 files changed, 11 insertions, 5 deletions
diff --git a/challenge-097/abigail/perl/ch-1.pl b/challenge-097/abigail/perl/ch-1.pl
index 9ffda0a6e5..eabc49db2c 100644
--- a/challenge-097/abigail/perl/ch-1.pl
+++ b/challenge-097/abigail/perl/ch-1.pl
@@ -14,13 +14,19 @@ use experimental 'lexical_subs';
#
#
-# Run as: perl ch-1.pl < input-file
+# Run as: perl ch-1.pl -t TIMES < input-file
#
+use Getopt::Long;
+
+GetOptions 't=i' => \my $times;
+
+die "-t option required" unless defined $times;
+
+$times %= 26;
+
while (<>) {
chomp;
- my ($times, $plain) = split ' ', $_, 2;
- $times %= 26;
- $plain =~ y/A-Z/ZA-Y/ for 1 .. $times;
- say $plain;
+ s/([A-Z])/my $ch = ord ($1) - $times; $ch += 26 if $ch < 65; chr $ch/eg;
+ say;
}