develooper Front page | perl.perl6.users | Postings from February 2021

REPL-specific issue with stored regex variable?

Thread Next
From:
William Michels via perl6-users
Date:
February 4, 2021 18:59
Subject:
REPL-specific issue with stored regex variable?
Message ID:
CAA99HCxhF_wCjL+6+Q1W9Jjg_5L4974FjfCw1BWYx_Kwgao5Fw@mail.gmail.com
Hello, I'm wondering if there's a REPL-specific issue with the following
docs.raku.org code? The code can be found at:
https://docs.raku.org/language/regexes#Regex_interpolation

> my $string   = 'Is this a regex or a string: 123\w+False$pattern1 ?';
Is this a regex or a string: 123\w+False$pattern1 ?
> my $regex    = /\w+/;
/\w+/
> say $string.match: / $regex /; #  EXPECTED OUTPUT: «「Is」␤»
Regex object coerced to string (please use .gist or .raku to do that)
  in any metachar at
/Users/homedir/rakudo/rakudo-2020.10/install/share/nqp/lib/NQPP6QRegex.moarvm
line 1
  in any termseq at
/Users/homedir/rakudo/rakudo-2020.10/install/share/nqp/lib/NQPP6QRegex.moarvm
line 1
  in any quote:sym</ /> at
/Users/homedir/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1
  in any quote at
/Users/homedir/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1
  in any value:sym<quote> at
/Users/homedir/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1
  in any value at
/Users/homedir/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1
  in any term:sym<value> at
/Users/homedir/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1
  in any term at
/Users/homedir/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1

「」
> $*VM
moar (2020.10)
>

I can get the .match code to work in the REPL by removing the forward
slashes and/or using a smartmatch operator:
> say $string ~~ $regex ;
「Is」
> say $string.match: $regex ;
「Is」
> say $string.match(:g, $regex) ;
(「Is」 「this」 「a」 「regex」 「or」 「a」 「string」 「123」 「w」 「False」 「pattern1」)

The problematic REPL line seems to work just fine in a standalone script,
so any feedback appreciated.

Thanks, Bill.

W. Michels, Ph.D.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About