diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-10-21 09:56:40 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-21 09:56:40 +0100 |
| commit | 6fc35c690d937c077ffc9a27161f26b7aae6eca8 (patch) | |
| tree | 376e91a704a748c56da20b004e3bd1f4892c5c63 | |
| parent | 0241d0e8287a3da592a614463aaaa34dba2d5945 (diff) | |
| parent | 742e0cf623a851aafa3708b57b65ac15493186fc (diff) | |
| download | perlweeklychallenge-club-6fc35c690d937c077ffc9a27161f26b7aae6eca8.tar.gz perlweeklychallenge-club-6fc35c690d937c077ffc9a27161f26b7aae6eca8.tar.bz2 perlweeklychallenge-club-6fc35c690d937c077ffc9a27161f26b7aae6eca8.zip | |
Merge pull request #2588 from vinodk89/master
Solution for challenge 83 - Task#1
| -rw-r--r-- | challenge-083/vinod-k/perl/ch-1.pl | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/challenge-083/vinod-k/perl/ch-1.pl b/challenge-083/vinod-k/perl/ch-1.pl new file mode 100644 index 0000000000..dc90f54f42 --- /dev/null +++ b/challenge-083/vinod-k/perl/ch-1.pl @@ -0,0 +1,33 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Data::Dumper; + +use feature 'say'; + +my $string = $ARGV[0]; + +die "Please enter a string with alteast three words.\n" unless $string; + +my @whole_string = split ' ', $string; + +die "String should have atleast three words.\n" unless (scalar @whole_string >= 3); + +##Remove first and last words from string with space +$string =~ s/^\S+\s*//; +$string =~ s/\s*\S+$//; + +my @taken = split ' ', $string; + +say "Taken words:\n".Dumper(\@taken); + +my $count = 0; + +foreach my $w ( @taken ) { + my @n = split //, $w; + $count += @n; +} + +say "Count : $count"; |
