aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-09-29 12:35:29 +0100
committerGitHub <noreply@github.com>2025-09-29 12:35:29 +0100
commit55492fbe509d00d359f9ae4e620c0562fdb9bf41 (patch)
treed8c00c2594fb414b952d01e84bd874c3e5ce18ce
parentdd9dab4686fc230480c1ba07dc81492311c1d41f (diff)
parente5b571e9bb9f221433b1e59f9ad3e747af5f6447 (diff)
downloadperlweeklychallenge-club-55492fbe509d00d359f9ae4e620c0562fdb9bf41.tar.gz
perlweeklychallenge-club-55492fbe509d00d359f9ae4e620c0562fdb9bf41.tar.bz2
perlweeklychallenge-club-55492fbe509d00d359f9ae4e620c0562fdb9bf41.zip
Merge pull request #12747 from zapwai/branch-for-341
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);