diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-11-14 02:10:39 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-14 02:10:39 +0000 |
| commit | 0a1de5baac9c26af3cb7305bdf4e7593dd15ec5f (patch) | |
| tree | 6b5815bedee9d2da040d3805bc52e3f7f391f5ee | |
| parent | a62b710e8f6c3cee01a37b3edcb3a432a0a53fe3 (diff) | |
| parent | e95fba85ee5aef0d473dbe410ae70d1fd870d53f (diff) | |
| download | perlweeklychallenge-club-0a1de5baac9c26af3cb7305bdf4e7593dd15ec5f.tar.gz perlweeklychallenge-club-0a1de5baac9c26af3cb7305bdf4e7593dd15ec5f.tar.bz2 perlweeklychallenge-club-0a1de5baac9c26af3cb7305bdf4e7593dd15ec5f.zip | |
Merge pull request #7077 from Solathian/branch-for-challenge-190
Added file for challange 190
| -rw-r--r-- | challenge-190/solathian/perl/ch-1.pl | 49 |
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); |
