aboutsummaryrefslogtreecommitdiff
path: root/challenge-282/dave-jacoby/perl/ch-2.pl
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-282/dave-jacoby/perl/ch-2.pl')
-rw-r--r--challenge-282/dave-jacoby/perl/ch-2.pl29
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-282/dave-jacoby/perl/ch-2.pl b/challenge-282/dave-jacoby/perl/ch-2.pl
new file mode 100644
index 0000000000..ee38c2bc28
--- /dev/null
+++ b/challenge-282/dave-jacoby/perl/ch-2.pl
@@ -0,0 +1,29 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ fc say postderef signatures state };
+
+my @examples = ( # added a couple test entries
+
+ qw{ pPeERrLl rRr GoO }
+);
+
+for my $input (@examples) {
+ my $output = changing_keys($input);
+ say <<"END";
+ Input: \$str = "$input"
+ Output: $output
+END
+}
+
+sub changing_keys ($input) {
+ my $c = 0;
+ my $len = -1 + length $input;
+ for my $i ( 1 .. $len ) {
+ my $l = fc substr $input, $i - 1, 1;
+ my $t = fc substr $input, $i, 1;
+ $c++ if $l ne $t;
+ }
+ return $c;
+}