From 31d4a39535f598631f10256e69de791635571eb2 Mon Sep 17 00:00:00 2001 From: vinodk89 Date: Wed, 21 Oct 2020 13:56:10 +0530 Subject: Solution for challenge 83 - Task#1 --- challenge-083/vinod-k/perl/ch-1.pl | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 challenge-083/vinod-k/perl/ch-1.pl 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"; -- cgit