use strict; use warnings; sub rel_cap { my ($ofs) = @_; substr($_, $-[$ofs], $+[$ofs] - $-[$ofs] +) } sub parser { local our @stack; local our @rv; my $parser = qr{ ^ (?&expr) (?&expr) \z (?{ @rv = @stack; }) (?(DEFINE) (?<expr> (.) (.) (?{ local @stack = (@stack, rel_cap(-2) . "|" . rel_cap(-1) ); }) ) ) }x; return $_[0] =~ /$parser/ && \@rv; } my $rv = parser('abcd'); print("$_\n") for @$rv;
a|b c|d
Update: Nevermind. @- and/or @+ become all wonky if there's a (?&...) inside the (?<...>...).
Even something as simple as the following fails:
(?<expr> (?&foo) (.) (?{ local @stack = (@stack, rel_cap(-1) ); }) ) (?<foo> . )
In reply to Re: Backreference variables in code embedded inside Perl 5.10 regexps (try2)
by ikegami
in thread Backreference variables in code embedded inside Perl 5.10 regexps
by casiano
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |