Hi,

El sáb., 2 feb. 2019 a las 7:48, ToddAndMargo via perl6-users (<
perl6-us...@perl.org>) escribió:

> Hi All,
>
> How do I use chr inside a regex.  In the below, how
> do I get rid of $y?
>
> $ p6 'my Str $x=chr(0x66)~chr(0x77); my Str $y=chr(0x66)~chr(0x77);
> $x~~s/ $y /xy/; say $x;'
>
> If what you want to do is precisely what you are doing, you don't even
need to use chr:

my $x = "\x66\x77"; $x ~~ s/\x66\x77/xy/; say $x # OUTPUT: «xy␤»

(See the document on quoting:
https://docs.perl6.org/language/quoting#Interpolation:_qq)

However, if what you want to do is what you _say_ you are doing,

my $x = "\x66\x77"; $x ~~ s/$(chr(0x66)~chr(0x77))/xy/; say $x; # OUTPUT:
«xy␤»

$() interpolates within a regex, as indicated in the documentation:
https://docs.perl6.org/language/regexes#index-entry-regex__Regex_Interpolation-Regex_interpolation

Cheers

JJ

Reply via email to