From a08eff7fea070be1ab0394c5a2bc83bed12a4c8c Mon Sep 17 00:00:00 2001 From: Steven Wilson Date: Tue, 20 Oct 2020 17:49:27 +0100 Subject: add solution for week 83 task 1 --- challenge-083/steven-wilson/perl/ch-1.pl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 challenge-083/steven-wilson/perl/ch-1.pl diff --git a/challenge-083/steven-wilson/perl/ch-1.pl b/challenge-083/steven-wilson/perl/ch-1.pl new file mode 100644 index 0000000000..5ff7841102 --- /dev/null +++ b/challenge-083/steven-wilson/perl/ch-1.pl @@ -0,0 +1,19 @@ +#!/usr/bin/env perl +# Week 83 Task 1 solution by Steven Wilson. + +use strict; +use warnings; +use Test::More; + +my $ex1_t = "The Weekly Challenge"; +my $ex2_t = "The purpose of our lives is to be happy"; +ok( length_of_excerpt($ex1_t) == 6, 'Example 1' ); +ok( length_of_excerpt($ex2_t) == 23, 'Example 2' ); +done_testing(); + +sub length_of_excerpt { + my $input = shift; + $input =~ s/^\w+|\w+$//g; # trim first and last words + $input =~ s/\s//g; # remove whitespace + return length $input; +} -- cgit