Perl Weekly Challenge 99: overlapping searches

One way to let me improve my knowledge about Raku (aka Perl 6) is to implement programs in it. Unluckily, I don’t have any production code to implement in Raku yet (sob!). So, why not try solving the Perl Weekly Challenge tasks?

In the following, the assigned tasks for Challenge 99.

My eyes…

My last check revealed that there could be a hope, but I have to wait one year since the surgery to let the eye to stabilize. After that period, something could be tried.
Better than nothing!

PWC 99 - Task 1

The first task required to write a program that accepts a shell-like string pattern, where * means any char and ? means a single character.
I’ve decided to convert the input pattern into a regular expression, with appropriate anchors, and then let Raku do the heavy work for me:

sub MAIN( Str $S, Str $P ) {
    # substitute every ? to match a single char
    # and every * to match a stream of chars
    # and add anchors
    my $regexp = '^' ~ $P.subst( '*', '.*' ).subst( '?', '.' ) ~ '$';
    { say 1; exit; } if $S ~~ / <$regexp> /;
    say 0;

The idea is that a pattern like a*b?c is translated into the regular expression ^a.*b.c$, so that the matchin engine can work.

PWC 99 - Task 2

The second task is more complex to me, and I was unable to fully complete it. The task required to search for all unique substrings that can be found into another string by composing single characters.
After a lot of work with arrays, I decide to use :exhausistive option of regular expression, that finds me almost all the required substring matches, but not the right solution:_

sub MAIN( Str $S, Str $T ) {
    my $counter = 0;
    my $regexp = $T.comb.join( '.*' );

    # overlapping search
    given $S {
        for m:exhaustive/ <$regexp> / -> $match {

    say $counter;

I do compile the string placing a .* between every character, and asking the matching engine to work for me. *Again, this is not a completely working solution, but I cannot come up with a better solution right now.

The article Perl Weekly Challenge 99: overlapping searches has been posted by Luca Ferrari on February 8, 2021