aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2021-02-09 17:21:48 -0500
committerDave Jacoby <jacoby.david@gmail.com>2021-02-09 17:21:48 -0500
commitfe8bf82ab0300914ba58aa60d84e16ddbf7a921d (patch)
tree33196fc1328cd1ee1cd7d3b2d73dba676768dca5
parent623bce98290cdba0b37fa6e4fda42b1222188682 (diff)
downloadperlweeklychallenge-club-fe8bf82ab0300914ba58aa60d84e16ddbf7a921d.tar.gz
perlweeklychallenge-club-fe8bf82ab0300914ba58aa60d84e16ddbf7a921d.tar.bz2
perlweeklychallenge-club-fe8bf82ab0300914ba58aa60d84e16ddbf7a921d.zip
additions
-rw-r--r--challenge-099/dave-jacoby/perl/ch-1.pl22
-rw-r--r--challenge-099/dave-jacoby/perl/ch-2.pl3
2 files changed, 21 insertions, 4 deletions
diff --git a/challenge-099/dave-jacoby/perl/ch-1.pl b/challenge-099/dave-jacoby/perl/ch-1.pl
index 465034f599..afc18c48b7 100644
--- a/challenge-099/dave-jacoby/perl/ch-1.pl
+++ b/challenge-099/dave-jacoby/perl/ch-1.pl
@@ -21,8 +21,26 @@ for my $n (@arr) {
sub pattern_match ( $S, $P ) {
my $pattern = $P;
- $pattern =~ s/\*/.*/g;
- $pattern =~ s/\?/.?/g;
+
+ # this was my first pass on this part
+ # $pattern =~ s/\*/.*/g;
+ # $pattern =~ s/\?/.?/g;
+ #
+ # a comment from Jonas Berlin (xkr47)
+ # made me reconsider. By the rules of the
+ # task, ? is ONE character and * is MANY
+ # CHARACTERS, but in Perl's regular
+ # expressions, .? is ZERO OR ONE CHARACTER
+ # and .* is ZERO OR MORE CHARACTERS
+ # to get ONE OR MORE CHARACTERS, we instead
+ # use .+ and to get ONE CHARACTER, we use .
+ #
+ # but of course, we need to match the WHOLE
+ # string, so we're matching the beginning (^)
+ # and the end ($)
+
+ $pattern =~ s/\*/.+/g;
+ $pattern =~ s/\?/./g;
$pattern = qq{^$pattern\$};
return $S =~ /$pattern/mix ? 1 : 0;
}
diff --git a/challenge-099/dave-jacoby/perl/ch-2.pl b/challenge-099/dave-jacoby/perl/ch-2.pl
index 65ba78ecd8..aabda6b46c 100644
--- a/challenge-099/dave-jacoby/perl/ch-2.pl
+++ b/challenge-099/dave-jacoby/perl/ch-2.pl
@@ -11,6 +11,7 @@ use List::Util qw{ uniq };
my @arr;
push @arr, [ 'littleit', 'lit' ];
push @arr, [ 'london', 'lon' ];
+push @arr, [ 'abracadabra', 'abra' ];
for my $n (@arr) {
my @p = unique_sub( $n->@* );
@@ -53,8 +54,6 @@ sub display_sub ( $string, $key ) {
for my $i ( 0 .. length $string ) {
my $l = substr( $string, $i, 1 );
my $k = $key{$i} || 0;
- my $L = $k ? uc $l : $l;
- # $output .= $L;
$output .= ' [' if $state == 0 && $k == 1;
$output .= '] ' if $state == 1 && $k == 0;