aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-099/x1mandi/perl/ch1.pl37
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-099/x1mandi/perl/ch1.pl b/challenge-099/x1mandi/perl/ch1.pl
new file mode 100755
index 0000000000..3e43f803fa
--- /dev/null
+++ b/challenge-099/x1mandi/perl/ch1.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use diagnostics;
+use utf8;
+use 5.20.0;
+#use re "debug";
+
+my $s = $ARGV[0];
+my $p = $ARGV[1];
+
+if (defined $s && defined $p) {
+ say look_for_pattern($s, $p);
+}
+
+
+sub look_for_pattern {
+ my ($s, $p) = @_;
+ #This is to replace ? to . in the regex.
+ $p =~ s/\?/./g;
+ #Add an anchor to fix the end until regex is looking for a match.
+ my $pattern = qr/$p$/;
+ say $pattern;
+ if ( $s =~ $pattern ) {
+ return(1);
+ } else {
+ return(0) }
+}
+
+#Testing the given examples from PWC
+my $str = "abcde";
+say look_for_pattern($str, "a*e");
+say look_for_pattern($str, "a*d");
+say look_for_pattern($str, "?b*d");
+say look_for_pattern($str, "a*c?e");
+