From 98f809b4b044d5b0d79ebb543d496680e379bf33 Mon Sep 17 00:00:00 2001 From: threadless-screw Date: Tue, 6 Aug 2019 23:23:28 +0200 Subject: [PATCH] Deletion of regex-interpolation trap section --- doc/Language/traps.pod6 | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/doc/Language/traps.pod6 b/doc/Language/traps.pod6 index 5a2791f67..5773aa449 100644 --- a/doc/Language/traps.pod6 +++ b/doc/Language/traps.pod6 @@ -921,47 +921,6 @@ of the assignment operators instead: =head1 Regexes -=head2 C«<{$x}>» vs C«$($x)»: Implicit EVAL - -Sometimes you may need to match a generated string in a regex. This can be done -using C<$(…)> or C«<{…}>» syntax: - -=for code -my $x = ‘ailemac’; -say ‘I ♥ camelia’ ~~ / $($x.flip) /; # OUTPUT: «「camelia」␤» -say ‘I ♥ camelia’ ~~ / <{$x.flip}> /; # OUTPUT: «「camelia」␤» - -However, the latter only works I. - -Internally C«<{…}>» EVAL-s the given string inside an anonymous regex, while -C<$(…)> lexically interpolates the given string. So C«<{…}>» immediately breaks -with more complicated inputs. For example: - -=for code -my $x = ‘ailemac#’; -say ‘I ♥ #camelia’ ~~ / $($x.flip) /; # OUTPUT: «「#camelia」␤» -# ⚠ ↓↓ WRONG ↓↓ ⚠ -say ‘I ♥ #camelia’ ~~ / <{$x.flip}> /; -# OUTPUT: -# ===SORRY!=== -# Regex not terminated. -# at EVAL_0:1 -# ------> anon regex { #camelia}⏏ -# Malformed regex -# at EVAL_0:1 -# ------> anon regex { #camelia}⏏ -# expecting any of: -# infix stopper - -Therefore, try not to use C«<{}>» unless you really need EVAL. - -Note that even though EVAL is normally considered unsafe, in this case -it is restricted to a set of safe operations (which is why it works -without L pragma). -In theory, careless use of C«<{}>» will only result in an exception being -thrown, and should not introduce security issues. - =head2 C<|> vs C<||>: which branch will win To match one of several possible alternatives, C<||> or C<|> will be used. But