aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-330/perlboy1967/perl/ch1.pl32
-rwxr-xr-xchallenge-330/perlboy1967/perl/ch2.pl30
2 files changed, 62 insertions, 0 deletions
diff --git a/challenge-330/perlboy1967/perl/ch1.pl b/challenge-330/perlboy1967/perl/ch1.pl
new file mode 100755
index 0000000000..6c36119f96
--- /dev/null
+++ b/challenge-330/perlboy1967/perl/ch1.pl
@@ -0,0 +1,32 @@
+#!/bin/perl
+
+=pod
+
+L<https://theweeklychallenge.org/blog/perl-weekly-challenge-330#TASK1>
+
+Author: Niels 'PerlBoy' van Dijke
+
+Task 1: Clear Digits
+Submitted by: Mohammad Sajid Anwar
+
+You are given a string containing only lower case English letters and digits.
+
+Write a script to remove all digits by removing the first digit and the closest
+non-digit character to its left.
+
+=cut
+
+use Test2::V0 qw(-no_srand);
+use exact 'v5.32', -signatures;
+
+sub clearDigits ($str) {
+ 1 while ($str =~ s#[a-z][0-9]##);
+ return $str;
+}
+
+is(clearDigits('cab12'),'c','Example 1');
+is(clearDigits('xy99'),'','Example 2');
+is(clearDigits('pa1erl'),'perl','Example 3');
+is(clearDigits('1a2b3c'),'1c','Own Example');
+
+done_testing;
diff --git a/challenge-330/perlboy1967/perl/ch2.pl b/challenge-330/perlboy1967/perl/ch2.pl
new file mode 100755
index 0000000000..f5393b611c
--- /dev/null
+++ b/challenge-330/perlboy1967/perl/ch2.pl
@@ -0,0 +1,30 @@
+#!/bin/perl
+
+=pod
+
+L<https://theweeklychallenge.org/blog/perl-weekly-challenge-330#TASK2>
+
+Author: Niels 'PerlBoy' van Dijke
+
+Task 2: Title Capital
+Submitted by: Mohammad Sajid Anwar
+
+You are given a string made up of one or more words separated by a single space.
+
+Write a script to capitalise the given title. If the word length is 1 or 2 then convert
+the word to lowercase otherwise make the first character uppercase and remaining lowercase.
+
+=cut
+
+use Test2::V0 qw(-no_srand);
+use exact 'v5.32', -signatures;
+
+sub titleCapital ($str) {
+ join ' ',map { length($_) <= 2 ? $_ : ucfirst } split /\s+/,lc $str;
+}
+
+is(titleCapital('PERL IS gREAT'),'Perl is Great','Example 1');
+is(titleCapital('THE weekly challenge'),'The Weekly Challenge','Example 2');
+is(titleCapital('YoU ARE A stAR'),'You Are a Star','Example 3');
+
+done_testing;