On 2/1/19 11:32 PM, JJ Merelo wrote:
El sáb., 2 feb. 2019 a las 7:48, ToddAndMargo via perl6-users
(<email@example.com <mailto:firstname.lastname@example.org>>) escribió:
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:
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; #
$() interpolates within a regex, as indicated in the documentation: