ikegami has asked for the wisdom of the Perl Monks concerning the following question:
The following works as expected:
use strict; use warnings; my $re; $re = qr/ (\d) (?{ print("[$1]\n") }) /x; 'thr33' =~ $re; __END__ output ====== [3]
However, it stops working when I start nesting regexps:
use strict; use warnings; my $re0; my $re1; $re1 = qr/ (\d) (?{ print("[$1]\n") }) /x; $re0 = qr/ (??{ $re1 }) /x; 'thr33' =~ $re0; __END__ output ====== Use of uninitialized value in concatenation (.) or string at (re_eval +1) line 1. []
Does anyone know of any workaround I can use?
$-[0] doesn't work:
use strict; use warnings; my $re0; my $re1; $re1 = qr/ (\d) (?{ print("[$-[0]]\n") }) /x; $re0 = qr/ (??{ $re1 }) (??{ $re1 }) /x; 'thr33' =~ $re0; __END__ output ====== [3] [3] expected ======== [3] [4]
$+ doesn't work either. It's undef.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using a capture in /(?{...})/
by ikegami (Patriarch) on Jul 25, 2005 at 21:35 UTC | |
by ikegami (Patriarch) on Jul 25, 2005 at 21:58 UTC | |
by japhy (Canon) on Jul 25, 2005 at 22:09 UTC | |
by ikegami (Patriarch) on Jul 26, 2005 at 00:07 UTC | |
|
Re: Using a capture in /(?{...})/
by ikegami (Patriarch) on Jul 25, 2005 at 21:18 UTC | |
|
Re: Using a capture in /(?{...})/
by tphyahoo (Vicar) on Jul 26, 2005 at 08:26 UTC | |
|
Re: Using a capture in /(?{...})/
by halley (Prior) on Jul 26, 2005 at 13:16 UTC |