diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2020-10-19 09:01:43 +0200 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2020-10-23 23:24:36 +0200 |
| commit | f98e136cf6640a065c866d37c5eafa045b43369b (patch) | |
| tree | cd4a3ca5f1ba1d82b9dd443cdae1e788d036b73a /challenge-083/jo-37/perl | |
| parent | 89421f14095148aefcd254da3d728b6150b22cc3 (diff) | |
| download | perlweeklychallenge-club-f98e136cf6640a065c866d37c5eafa045b43369b.tar.gz perlweeklychallenge-club-f98e136cf6640a065c866d37c5eafa045b43369b.tar.bz2 perlweeklychallenge-club-f98e136cf6640a065c866d37c5eafa045b43369b.zip | |
Solution to task 1
Diffstat (limited to 'challenge-083/jo-37/perl')
| -rwxr-xr-x | challenge-083/jo-37/perl/ch-1.pl | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/challenge-083/jo-37/perl/ch-1.pl b/challenge-083/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..ccacecf211 --- /dev/null +++ b/challenge-083/jo-37/perl/ch-1.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl + +use Test2::V0; + +sub inner_length { + local $_ = shift; + + # Split the string into words, pick all between the first and the + # last, join them and return the length. + length join '', splice @{[split qr{\s+}]}, 1, -1; + +} + +is inner_length('The Weekly Challenge'), 6, 'Example 1'; +is inner_length('The purpose of our lives is to be happy'), 23, 'Example 2'; +is inner_length('nothing intermediate'), 0, 'Out of scope: no inner words'; + +done_testing; |
