From 34cb0e39c0844822f8da3cae9b101fbd161f3768 Mon Sep 17 00:00:00 2001 From: Andreas Mahnke Date: Tue, 15 Jul 2025 15:52:15 +0200 Subject: Challenge 330 --- challenge-330/mahnkong/perl/ch-1.pl | 14 ++++++++++++++ challenge-330/mahnkong/perl/ch-2.pl | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 challenge-330/mahnkong/perl/ch-1.pl create mode 100644 challenge-330/mahnkong/perl/ch-2.pl diff --git a/challenge-330/mahnkong/perl/ch-1.pl b/challenge-330/mahnkong/perl/ch-1.pl new file mode 100644 index 0000000000..8063b02757 --- /dev/null +++ b/challenge-330/mahnkong/perl/ch-1.pl @@ -0,0 +1,14 @@ +use strict; +use warnings; +use feature 'signatures'; +use Test::More 'no_plan'; + +sub run($str) { + $str =~ s/\D?\d// while $str =~ /\D?\d/; + return $str; +} + +is(run('cab12'), 'c', "Example 1"); +is(run('xy99'), '', "Example 2"); +is(run('pa1erl'), 'perl', "Example 3"); +is(run('ab132x'), 'x', "Example 4"); diff --git a/challenge-330/mahnkong/perl/ch-2.pl b/challenge-330/mahnkong/perl/ch-2.pl new file mode 100644 index 0000000000..904af50abf --- /dev/null +++ b/challenge-330/mahnkong/perl/ch-2.pl @@ -0,0 +1,17 @@ +use strict; +use warnings; +use feature 'signatures'; +use Test::More 'no_plan'; + +sub run($string) { + my @result; + while ($string =~ /(\S+)/g) { + push @result, lc($1); + $result[-1] = ucfirst($result[-1]) if length($result[-1]) > 2; + } + return join(" ", @result); +} + +is(run("PERL IS gREAT"), "Perl is Great", "Example 1"); +is(run("THE weekly challenge"), "The Weekly Challenge", "Example 2"); +is(run("YoU ARE A stAR"), "You Are a Star", "Example 3"); -- cgit