aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-083/vinod-k/perl/ch-1.pl33
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";