diff options
| author | Abigail <abigail@abigail.be> | 2021-01-26 01:13:15 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-01-26 12:07:41 +0100 |
| commit | 1889deddca521e1aa013d53a749c693c6589deba (patch) | |
| tree | 74ad27d14ee32de3ad6a5afdd04f895a280ddf10 /challenge-097/abigail/perl | |
| parent | 6c5715542385de49f20d0f56d1c9aa66b5736cab (diff) | |
| download | perlweeklychallenge-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.pl | 16 |
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; } |
