diff options
| -rw-r--r-- | challenge-330/zapwai/perl/ch-1.pl | 35 | ||||
| -rw-r--r-- | challenge-330/zapwai/perl/ch-2.pl | 32 |
2 files changed, 67 insertions, 0 deletions
diff --git a/challenge-330/zapwai/perl/ch-1.pl b/challenge-330/zapwai/perl/ch-1.pl new file mode 100644 index 0000000000..62852c81e3 --- /dev/null +++ b/challenge-330/zapwai/perl/ch-1.pl @@ -0,0 +1,35 @@ +use v5.38; + +sub proc($str) { + say "Input: $str"; + my $ind = 0; + my $flag = 1; + my $o = $str; + while ($flag) { + my @l = split '', $o; + if ($o =~ /\d/) { + if ($l[0] =~ /\d/) { + $flag = 0; + } else { + for my $i (0 .. $#l - 1) { + if ($l[$i+1] =~ /\d/) { + $o = substr($o, 0, $i).substr($o, $i + 2); + last; + } + } + } + } else { + $flag = 0; + } + } + say "Output: $o"; +} + +my $str = "cab12"; +proc($str); + +$str = "xy99"; +proc($str); + +$str = "pa1erl"; +proc($str); diff --git a/challenge-330/zapwai/perl/ch-2.pl b/challenge-330/zapwai/perl/ch-2.pl new file mode 100644 index 0000000000..da2aafddc3 --- /dev/null +++ b/challenge-330/zapwai/perl/ch-2.pl @@ -0,0 +1,32 @@ +use v5.38; + +sub capitalize($w) { + my $a = substr $w, 0, 1; + my $b = substr $w, 1; + return uc($a).lc($b); + +} + +sub proc($str) { + say "Input: $str"; + my @words = split(" ", $str); + my @out; + foreach my $word (@words) { + if (length $word < 3) { + push @out, lc($word); + } else { + push @out, capitalize($word); + } + } + my $o = join " ", @out; + say "Output: $o"; +} + +my $str = "PERL IS gREAT"; +proc($str); + +$str = "THE weekly challenge"; +proc($str); + +$str = "YoU ARE A stAR"; +proc($str); |
