diff options
| author | wanderdoc <wanderdoc@users.noreply.github.com> | 2025-07-15 14:03:00 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-15 14:03:00 +0200 |
| commit | 034eec76779cb81892537fd7d41def0779d35fd7 (patch) | |
| tree | dab10010971e9d964037f0652c48b1e1f8e56855 | |
| parent | b16659a7afb35fa8f0359d98c8f4db7b0a66951f (diff) | |
| download | perlweeklychallenge-club-034eec76779cb81892537fd7d41def0779d35fd7.tar.gz perlweeklychallenge-club-034eec76779cb81892537fd7d41def0779d35fd7.tar.bz2 perlweeklychallenge-club-034eec76779cb81892537fd7d41def0779d35fd7.zip | |
Create ch-2.pl
| -rw-r--r-- | challenge-330/wanderdoc/perl/ch-2.pl | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/challenge-330/wanderdoc/perl/ch-2.pl b/challenge-330/wanderdoc/perl/ch-2.pl new file mode 100644 index 0000000000..be72299b53 --- /dev/null +++ b/challenge-330/wanderdoc/perl/ch-2.pl @@ -0,0 +1,40 @@ +#!perl +use strict; +use warnings FATAL => qw(all); + +=prompt +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. + +Example 1 + +Input: $str = "PERL IS gREAT" +Output: "Perl is Great" + + +Example 2 + +Input: $str = "THE weekly challenge" +Output: "The Weekly Challenge" + + +Example 3 + +Input: $str = "YoU ARE A stAR" +Output: "You Are a Star" +=cut + +use Test2::V0 -no_srand => 1; + +is(task_330_2("PERL IS gREAT"), "Perl is Great", "Example 1"); +is(task_330_2("THE weekly challenge"), "The Weekly Challenge", "Example 2"); +is(task_330_2("YoU ARE A stAR"), "You Are a Star", "Example 3"); +done_testing(); + +sub task_330_2 +{ + my $str = $_[0]; + return join(' ', + map {length($_) < 3 ? lc $_ : ucfirst(lc($_))} + split(/\s/, $str)); +} |
