aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Ferrone <zapwai@gmail.com>2025-09-28 22:23:01 -0400
committerGitHub <noreply@github.com>2025-09-28 22:23:01 -0400
commite5b571e9bb9f221433b1e59f9ad3e747af5f6447 (patch)
tree880c2467e06986a02764d4b85a05f65545730332
parentb35e6ce2c209fad4aed4c1cb66ea0840143cbed1 (diff)
downloadperlweeklychallenge-club-e5b571e9bb9f221433b1e59f9ad3e747af5f6447.tar.gz
perlweeklychallenge-club-e5b571e9bb9f221433b1e59f9ad3e747af5f6447.tar.bz2
perlweeklychallenge-club-e5b571e9bb9f221433b1e59f9ad3e747af5f6447.zip
Week 341
-rw-r--r--challenge-341/zapwai/perl/ch-1.pl34
-rw-r--r--challenge-341/zapwai/perl/ch-2.pl28
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);