-Code blocks within patterns are now parsed in the same pass as the
-surrounding code; in particular it is no longer necessary to have balanced
-braces: this now works:
-
- /(?{ $x='{' })/
-
-This means that this error message is longer generated:
-
- Sequence (?{...}) not terminated or not {}-balanced in regex
-
-but a new error may be seen:
-
- Sequence (?{...}) not terminated with ')'
-
-In addition, literal code blocks within run-time patterns are only
-compiled once, at perl compile-time:
-
- for my $p (...) {
- # this 'FOO' block of code is compiled once,
- # at the same time as the surrounding 'for' loop
- /$p{(?{FOO;})/;
- }
-
-=item *
-
-Lexical variables are now sane as regards scope, recursion and closure
-behavior. In particular, C</A(?{B})C/> behaves (from a closure viewpoint)
-exactly like C</A/ && do { B } && /C/>, while C<qr/A(?{B})C/> is like
-C<sub {/A/ && do { B } && /C/}>. So this code now works how you might
-expect, creating three regexes that match 0, 1, and 2:
-
- for my $i (0..2) {
- push @r, qr/^(??{$i})$/;
- }
- "1" =~ $r[1]; # matches
-
-=item *
-
-The C<use re 'eval'> pragma is now only required for code blocks defined
-at runtime; in particular in the following, the text of the C<$r> pattern is
-still interpolated into the new pattern and recompiled, but the individual
-compiled code-blocks within C<$r> are reused rather than being recompiled,
-and C<use re 'eval'> isn't needed any more:
-
- my $r = qr/abc(?{....})def/;
- /xyz$r/;
-
-=item *
-
-Flow control operators no longer crash. Each code block runs in a new
-dynamic scope, so C<next> etc. will not see any enclosing loops and
-C<caller> will not see any calling subroutines. C<return> returns a value
-from the code block, not from any enclosing subroutine.
-
-=item *
-
-Perl normally caches the compilation of run-time patterns, and doesn't
-recompile if the pattern hasn't changed, but this is now disabled if
-required for the correct behavior of closures. For example:
-
- my $code = '(??{$x})';
- for my $x (1..3) {
- # recompile to see fresh value of $x each time
- $x =~ /$code/;
- }
-
-
-=item *
-
-The C</msix> and C<(?msix)> etc. flags are now propagated into the return
-value from C<(??{})>; this now works:
-
- "AB" =~ /a(??{'b'})/i;
-
-=item *
-
-Warnings and errors will appear to come from the surrounding code (or for
-run-time code blocks, from an eval) rather than from an C<re_eval>:
-
- use re 'eval'; $c = '(?{ warn "foo" })'; /$c/;
- /(?{ warn "foo" })/;
-
-formerly gave:
-
- foo at (re_eval 1) line 1.
- foo at (re_eval 2) line 1.
-
-and now gives:
-
- foo at (eval 1) line 1.
- foo at /some/prog line 2.
-
-=back