diff options
| author | vinodk89 <vinodkk89@gmail.com> | 2020-10-21 13:56:10 +0530 |
|---|---|---|
| committer | vinodk89 <vinodkk89@gmail.com> | 2020-10-21 13:56:10 +0530 |
| commit | 31d4a39535f598631f10256e69de791635571eb2 (patch) | |
| tree | 2edae120651f66e35969999e0dfdd5875f7149d8 | |
| parent | d30a720b98071c032e4ee6629eb761651b99961e (diff) | |
| download | perlweeklychallenge-club-31d4a39535f598631f10256e69de791635571eb2.tar.gz perlweeklychallenge-club-31d4a39535f598631f10256e69de791635571eb2.tar.bz2 perlweeklychallenge-club-31d4a39535f598631f10256e69de791635571eb2.zip | |
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..d57620ba9a --- /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"; |
