diff options
| author | Niels van Dijke <perlboy@cpan.org> | 2025-07-21 09:56:27 +0000 |
|---|---|---|
| committer | Niels van Dijke <perlboy@cpan.org> | 2025-07-21 09:56:27 +0000 |
| commit | e5c80d78b7f4cf52d2f9abec9799c37ddd07ae09 (patch) | |
| tree | f41a53136e06a521e76a8fc4e6042639dd2cedfb | |
| parent | e0f7e800fc8f1b2cb50896852a0a3ed61980f510 (diff) | |
| download | perlweeklychallenge-club-e5c80d78b7f4cf52d2f9abec9799c37ddd07ae09.tar.gz perlweeklychallenge-club-e5c80d78b7f4cf52d2f9abec9799c37ddd07ae09.tar.bz2 perlweeklychallenge-club-e5c80d78b7f4cf52d2f9abec9799c37ddd07ae09.zip | |
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; |
