From fe8bf82ab0300914ba58aa60d84e16ddbf7a921d Mon Sep 17 00:00:00 2001 From: Dave Jacoby Date: Tue, 9 Feb 2021 17:21:48 -0500 Subject: additions --- challenge-099/dave-jacoby/perl/ch-1.pl | 22 ++++++++++++++++++++-- challenge-099/dave-jacoby/perl/ch-2.pl | 3 +-- 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; -- cgit