diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-07-22 00:21:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-22 00:21:05 +0100 |
| commit | 7c8598cf517d28e2e1edc8ee6446253193ff73ba (patch) | |
| tree | 0e0bc271c80bd4735703cfb224dbfdc59a74a755 | |
| parent | 2748da8e0f615f6545fed9fdebe74790638e27d9 (diff) | |
| parent | e5c80d78b7f4cf52d2f9abec9799c37ddd07ae09 (diff) | |
| download | perlweeklychallenge-club-7c8598cf517d28e2e1edc8ee6446253193ff73ba.tar.gz perlweeklychallenge-club-7c8598cf517d28e2e1edc8ee6446253193ff73ba.tar.bz2 perlweeklychallenge-club-7c8598cf517d28e2e1edc8ee6446253193ff73ba.zip | |
Merge pull request #12384 from PerlBoy1967/branch-for-challenge-330
w330 - Task 1 & 2 (forgotten to submit....)
| -rwxr-xr-x | challenge-330/perlboy1967/perl/ch1.pl | 32 | ||||
| -rwxr-xr-x | challenge-330/perlboy1967/perl/ch2.pl | 30 |
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; |
