Perl weekly challenge 97
Here are solutions to this weeks challenges from the Perl Weekly Challenge.
You can find my full code on Github
Challenge 1
You are given string $S containing alphabets A .. Z only and a number $N . Write a script to encrypt the given string $S using Caesar Cipher with left shift of size $N .Solution
sub caesar {
return $_[0] =~ s{([A-Z])}{chr 65+(-65-$_[1]+ord$1)%26}regex;
}
This is a simple one liner - but has some neat features - other than using "regex" for the switches, although most are important...
- r - return value rather than substitute in original string
- e - evaluate replace rather than use string
- g - repeat over all characters
- x - not needed (comments in match) - but looks good!
In the evaled replacement code - there is some clever ordering of values to reduce the need for brackets...

