diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2024-06-19 16:21:24 +0200 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2024-06-19 16:29:02 +0200 |
| commit | f07c9c9b2a4608cf36cfc1ee85c7aacd4b445eee (patch) | |
| tree | 3c9933a70a355daad32a534e93598f18680f2dc1 | |
| parent | ffc47a8850ee877978e371d11a01a028862a3f9d (diff) | |
| download | perlweeklychallenge-club-f07c9c9b2a4608cf36cfc1ee85c7aacd4b445eee.tar.gz perlweeklychallenge-club-f07c9c9b2a4608cf36cfc1ee85c7aacd4b445eee.tar.bz2 perlweeklychallenge-club-f07c9c9b2a4608cf36cfc1ee85c7aacd4b445eee.zip | |
Solution to task 1
| -rwxr-xr-x | challenge-274/jo-37/perl/ch-1.pl | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/challenge-274/jo-37/perl/ch-1.pl b/challenge-274/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..76d729a45b --- /dev/null +++ b/challenge-274/jo-37/perl/ch-1.pl @@ -0,0 +1,62 @@ +#!/usr/bin/perl -s + +use v5.24; +use Test2::V0; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die <<EOS unless @ARGV; +usage: $0 [-examples] [-tests] [SENTENCE] + +-examples + run the examples from the challenge + +-tests + run some tests + +SENTENCE + a sentence + +EOS + + +### Input and Output + +say qq{@{[goat_latin("@ARGV")]}}; + + +### Implementation +# +# For details see: +# https://github.sommrey.de/the-bears-den/2024/06/19/ch-274.html#task-1 + + +sub goat_latin { + my $na = 1; + no warnings 'uninitialized'; + shift =~ s#\s*\K(?i:([^aeiou])?)(\w+)#"$2$1m" . ("a" x ++$na)#ger +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is goat_latin("I love Perl"), "Imaa ovelmaaa erlPmaaaa", "example 1"; + is goat_latin("Perl and Raku are friends"), + "erlPmaa andmaaa akuRmaaaa aremaaaaa riendsfmaaaaaa", "example 2"; + is goat_latin("The Weekly Challenge"), "heTmaa eeklyWmaaa hallengeCmaaaa", + "example 3"; + } + + SKIP: { + skip "tests" unless $tests; + } + + done_testing; + exit; +} |
