diff options
| author | drbaggy <js5@sanger.ac.uk> | 2021-02-11 23:09:10 +0000 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2021-02-11 23:09:10 +0000 |
| commit | b6564e584726b76c7e107ef42b96ad94a0bd10e3 (patch) | |
| tree | d9e4a28996c2c5c9ae5cef80c1d8f4850e7e878c | |
| parent | df92c99c85ad0eef27c4dd77a2b135a41369f0c0 (diff) | |
| download | perlweeklychallenge-club-b6564e584726b76c7e107ef42b96ad94a0bd10e3.tar.gz perlweeklychallenge-club-b6564e584726b76c7e107ef42b96ad94a0bd10e3.tar.bz2 perlweeklychallenge-club-b6564e584726b76c7e107ef42b96ad94a0bd10e3.zip | |
whitespace
| -rw-r--r-- | challenge-099/james-smith/perl/ch-2.pl | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/challenge-099/james-smith/perl/ch-2.pl b/challenge-099/james-smith/perl/ch-2.pl index b22cf7e58f..d0a3231645 100644 --- a/challenge-099/james-smith/perl/ch-2.pl +++ b/challenge-099/james-smith/perl/ch-2.pl @@ -36,29 +36,30 @@ done_testing(); sub uniq_subseq { my( $str, $sub ) = @_; - my $f = substr $sub,0,1,''; + my $f = substr $sub, 0, 1, q(); return scalar @{[ $str =~ m{$f}g ]} if $sub eq q(); my $res = 0; - $res += uniq_subseq($str,$sub) while $str=~s{.*?$f}{}; + $res += uniq_subseq( $str, $sub ) while $str=~s{.*?$f}{}; return $res; } -say ''; -print join "\n", display_uniq_subseq( 'littleit', 'lit' ),'',''; -print join "\n", display_uniq_subseq( 'london', 'lon' ),'',''; -print join "\n", display_uniq_subseq( 'abcabcabc', 'abc' ),'',''; +say q(); + +print join "\n", display_uniq_subseq( 'littleit', 'lit' ), q(), q(); +print join "\n", display_uniq_subseq( 'london', 'lon' ), q(), q(); +print join "\n", display_uniq_subseq( 'abcabcabc', 'abc' ), q(), q(); sub display_uniq_subseq { - my( $str, $sub, $prev ) = (@_,''); + my( $str, $sub, $prev ) = ( @_, q() ); ## adding q() means previous is defined in first loop.... - return ($prev =~s{\]\[}{}gr).$str if $sub eq ''; ## If we have exhausted the substring we return the previous part (by collapse []s) + return ($prev =~s{\]\[}{}gr).$str if $sub eq q(); ## If we have exhausted the substring we return the previous part (by collapse []s) - my( $r, $t, @res ) = ( '\A(.*?)('.(substr $sub,0,1,'').')', q() ); ## regex collects anything before the matched letter & the matched letter + my( $r, $t, @res ) = ( '\A(.*?)('.(substr $sub, 0, 1, q()).')', q() ); ## regex collects anything before the matched letter & the matched letter while( $str =~ s{$r}{} ) { my($a,$b) = ($1,$2); - push @res, display_uniq_subseq( $str,$sub,$prev.$a.'['.$b.']' ); - $prev .= $a.$b; ## put the match onto the previous string, and look for subsequent match. + push @res, display_uniq_subseq( $str, $sub, $prev.$a.'['.$b.']' ); + $prev .= $a.$b; ## put the match onto the previous string, and continue to next match } return @res; } @@ -67,10 +68,10 @@ sub uniq_subseq_cache { my( $str, $sub ) = @_; my $k = "$str-$sub"; return $c->{$k} if exists $c->{$k}; - my $f = substr $sub,0,1,''; + my $f = substr $sub, 0, 1, q(); return $c->{$k} = scalar @{[ $str =~ m{$f}g ]} if $sub eq q(); my $res = 0; - $res += uniq_subseq($str,$sub) while $str=~s{.*?$f}{}; + $res += uniq_subseq( $str, $sub ) while $str=~s{.*?$f}{}; return $c->{$k} = $res; } |
