aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSolathian <horvath6@gmail.com>2022-11-14 00:29:05 +0100
committerSolathian <horvath6@gmail.com>2022-11-14 00:29:05 +0100
commite95fba85ee5aef0d473dbe410ae70d1fd870d53f (patch)
tree92da6456146c43bcd29f2aad3d127877d0a585cc
parent001ada3fa9633769b491b44938304c3c333cad1d (diff)
downloadperlweeklychallenge-club-e95fba85ee5aef0d473dbe410ae70d1fd870d53f.tar.gz
perlweeklychallenge-club-e95fba85ee5aef0d473dbe410ae70d1fd870d53f.tar.bz2
perlweeklychallenge-club-e95fba85ee5aef0d473dbe410ae70d1fd870d53f.zip
Added file for challange 190
-rw-r--r--challenge-190/solathian/perl/ch-1.pl49
1 files changed, 49 insertions, 0 deletions
diff --git a/challenge-190/solathian/perl/ch-1.pl b/challenge-190/solathian/perl/ch-1.pl
new file mode 100644
index 0000000000..f032c6d0d0
--- /dev/null
+++ b/challenge-190/solathian/perl/ch-1.pl
@@ -0,0 +1,49 @@
+#!usr/bin/perl -w
+use strict;
+use warnings;
+
+use feature qw(say signatures);
+no warnings qw(experimental);
+
+my $testsEnabled = 0;
+# Task 1: Capital Detection
+
+# You are given a string with alphabetic characters only: A..Z and a..z.
+
+# Write a script to find out if the usage of Capital is appropriate if it satisfies
+# at least one of the following rules:
+
+# 1) Only first letter is capital and all others are small.
+# 2) Every letter is small.
+# 3) Every letter is capital.
+
+sub capitalDetect($string)
+{
+ my $returnVal = 0;
+
+ if( $string =~ /^[A-Z]{1}[a-z]+$/ )
+ {
+ $returnVal = 1;
+ }
+ elsif( $string =~ /^[a-z]+$/ ) # not letting empty string to be valid
+ {
+ $returnVal = 1;
+ }
+ elsif( $string =~ /^[A-Z]+$/ ) # not letting empty string to be valid
+ {
+ $returnVal = 1;
+ }
+
+ return $returnVal;
+}
+
+# Examples:
+my $test0 = 'Perl'; # 1
+my $test1 = 'TPF'; # 1
+my $test2 = 'PyThon'; # 0
+my $test3 = 'raku'; # 1
+
+say capitalDetect($test0) if($testsEnabled);
+say capitalDetect($test1) if($testsEnabled);
+say capitalDetect($test2) if($testsEnabled);
+say capitalDetect($test3) if($testsEnabled);