diff options
| author | boblied <boblied@gmail.com> | 2020-10-25 11:04:12 -0500 |
|---|---|---|
| committer | boblied <boblied@gmail.com> | 2020-10-25 11:04:12 -0500 |
| commit | 2cdf46aacae1e1fa62e70bc7553f546119ca02d4 (patch) | |
| tree | 0ebcdf86a5de0060625c6d33889f50dc81635e0f /challenge-083 | |
| parent | d244e1d3a5e39ce0fad850b17c0b406ff462ebc1 (diff) | |
| download | perlweeklychallenge-club-2cdf46aacae1e1fa62e70bc7553f546119ca02d4.tar.gz perlweeklychallenge-club-2cdf46aacae1e1fa62e70bc7553f546119ca02d4.tar.bz2 perlweeklychallenge-club-2cdf46aacae1e1fa62e70bc7553f546119ca02d4.zip | |
Solution for PWC 083 Task 1
Diffstat (limited to 'challenge-083')
| -rwxr-xr-x | challenge-083/bob-lied/perl/ch-1.pl | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/challenge-083/bob-lied/perl/ch-1.pl b/challenge-083/bob-lied/perl/ch-1.pl new file mode 100755 index 0000000000..e1f95185ff --- /dev/null +++ b/challenge-083/bob-lied/perl/ch-1.pl @@ -0,0 +1,49 @@ +#!/usr/bin/env perl +# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu: +#============================================================================= +# ch-1.pl +#============================================================================= +# Copyright (c) 2020, Bob Lied +#============================================================================= +# Perl Weekly Challenge 083 Task #1 > Words Length +#============================================================================= +# 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. + +use strict; +use warnings; +use v5.30; + +use experimental qw/ signatures /; + +use Getopt::Long; + +sub Usage { "Usage: $0 'string of words'" }; + +my $Verbose = 0; +GetOptions('verbose' => \$Verbose); + +my $S = shift; + +die Usage() unless $S; + +# Trim leading white space. +$S =~ s/^\s+//; + +# Remove the first word -- anything that's not white space +$S =~ s/^\S+//; + +# Turn the string around. +$S = reverse($S); + +# Trim leading white space. +$S =~ s/^\s+//; + +# Remove the first word again. +$S =~ s/^\S+//; + +# Ignore white space. +$S =~ s/\s*//g; + +say length($S); |
