aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwanderdoc <wanderdoc@googlemail.com>2020-10-25 18:02:27 +0100
committerwanderdoc <wanderdoc@googlemail.com>2020-10-25 18:02:27 +0100
commit84d4eb6d2443b26a7202c7e76ac77cba35d8541a (patch)
tree278928b76a7308a8ddedfebe92855d57e1d713a2
parentee5492e4eb4d02517e8514e18c048c044df53b9e (diff)
downloadperlweeklychallenge-club-84d4eb6d2443b26a7202c7e76ac77cba35d8541a.tar.gz
perlweeklychallenge-club-84d4eb6d2443b26a7202c7e76ac77cba35d8541a.tar.bz2
perlweeklychallenge-club-84d4eb6d2443b26a7202c7e76ac77cba35d8541a.zip
Solution to task #1 challenge-083.
-rw-r--r--challenge-083/wanderdoc/perl/ch-1.pl35
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-083/wanderdoc/perl/ch-1.pl b/challenge-083/wanderdoc/perl/ch-1.pl
new file mode 100644
index 0000000000..608fff76f0
--- /dev/null
+++ b/challenge-083/wanderdoc/perl/ch-1.pl
@@ -0,0 +1,35 @@
+#!perl
+use strict;
+use warnings FATAL => qw(all);
+
+=prompt
+You are given a string $S with 3 or more words. Write a script to find the length of the string except the first and last words ignoring whitespace.
+Example 1: Input: $S = "The Weekly Challenge" Output: 6
+Example 2: Input: $S = "The purpose of our lives is to be happy" Output: 23
+=cut
+
+
+
+
+
+
+
+use List::Util qw(reduce);
+use Test::More;
+
+sub words_length
+{
+ my $string = $_[0];
+ my @words = split(/\s+/, $string);
+
+ shift @words;
+
+ pop @words;
+
+ my $length = reduce {$a + $b} map length, @words;
+ return $length;
+}
+
+is(words_length("The Weekly Challenge"), 6, 'Example 1');
+is(words_length("The purpose of our lives is to be happy"), 23, 'Example 1');
+done_testing(); \ No newline at end of file