Understood. Thankyou.

The " quotes is what I missed. So $<sol> = "@W[3]" worked as I would expect.

The other two variations, eg. $<sol> =<{ @W[3] }>, gave Nil responses, indicating match failure.

On 13/06/2020 14:41, Brad Gilbert wrote:
Inside of a regex `{…}` will just run some regular Raku code.
Code inside of it will most likely have no effect on what the regex matches.

What you should have written was:

    $<sol> = "@W[3]"

The thing you were thinking of was:

    $<sol> = <{ @W[3] }>

Which could have been written as:

    <sol={ @W[3] }>

---

To have the result of regular Raku code have an effect on the match, it has to have <…> around it

    'TrueFalse' ~~ / <{ Bool.pick }> /

I think it is better if you use "…" if you are just interpolating a variable, because that is something you might do outside of a regex as well.

---

The reason your code matched is that an empty regex always matches.

    'abc' ~~ / "" /
    'abc' ~~ / {} /
    'abc' ~~ / {'def'} / # still an empty regex as far as the regex engine is concerned

On Sat, Jun 13, 2020 at 5:35 AM Richard Hainsworth <rnhainswo...@gmail.com <mailto:rnhainswo...@gmail.com>> wrote:

    I was playing with a regex and array interpolation.

    From the documentation I thought the following comparisons would
    be the same, but they are not.

    What am I missing?

    my @W = <perl weekly challenge with some extra things>;
    my $S = 'perlchallengeextrathingswithweeklysome' ; #randomly concatenate 
the words without spaces say 'yes' if $S ~~ /
    $<sol>=( {@W[3] }) /;
    say $<sol>;
    my $sol = @W[3]; # with
    say 'yes' if $S ~~ / $<sol>=( $sol ) /;
    say $<sol>;

    <response>
    yes
    「」
    yes
    「with」



Reply via email to