diff options
| -rw-r--r-- | challenge-341/zapwai/perl/ch-1.pl | 34 | ||||
| -rw-r--r-- | challenge-341/zapwai/perl/ch-2.pl | 28 |
2 files changed, 62 insertions, 0 deletions
diff --git a/challenge-341/zapwai/perl/ch-1.pl b/challenge-341/zapwai/perl/ch-1.pl new file mode 100644 index 0000000000..868c0b1723 --- /dev/null +++ b/challenge-341/zapwai/perl/ch-1.pl @@ -0,0 +1,34 @@ +use v5.38; + +sub proc($s, @k) { + say "Input: \$s = $s, \@keys = @k"; + my @keys = map { lc } @k; + my @words = split ' ', $s; + my $cnt = 0; + for my $word (@words) { + for my $letter (@keys) { + if (lc($word) =~ /$letter/) { + $cnt++; + last; + } + } + } + my $o = scalar(@words) - $cnt; + say "Output: $o"; +} + +my $s = "Hello World"; +my @keys = ('d'); +proc($s, @keys); + +$s = "apple banana cherry"; @keys = ('a', 'e'); +proc($s, @keys); + +$s = "Coding is fun"; @keys = (); +proc($s, @keys); + +$s = "The Weekly Challenge"; @keys = ('a', 'b'); +proc($s, @keys); + +$s = "Perl and Python"; @keys = ('p'); +proc($s, @keys); diff --git a/challenge-341/zapwai/perl/ch-2.pl b/challenge-341/zapwai/perl/ch-2.pl new file mode 100644 index 0000000000..f229be0698 --- /dev/null +++ b/challenge-341/zapwai/perl/ch-2.pl @@ -0,0 +1,28 @@ +use v5.38; + +sub proc($s, $c) { + say "Input: \$str = $s, \$char = $c"; + my $ind = index $s, $c; + my $pre = substr $s, 0, $ind + 1; + my $post = substr $s, $ind + 1; + print "Output: "; + print scalar reverse $pre; + say $post; +} + +my $s = "programming"; +my $c = "g"; +proc($s, $c); + +$s = "hello"; +$c = "h"; +proc($s, $c); + +$s = "abcdefghij"; $c = "h"; +proc($s, $c); + +$s = "reverse"; $c = "s"; +proc($s, $c); + +$s = "perl"; $c = "r"; +proc($s, $c); |
