in reply to Using a capture in /(?{...})/
I found something that does work: pos (and $+[0]). Actually, argless pos works even if we're not operating on $_!
Therefore, this hack works:
use strict; use warnings; my $re0; my $re1; our $s_pos; $re1 = qr/ (?{ local $s_pos = pos; }) [A-Z] (?{ print("[", substr($_, $s_pos, pos()-$s_pos), "]\n") }) /x; $re0 = qr/ (??{ $re1 }) (??{ $re1 }) /x; 'abcDE' =~ $re0; __END__ output ====== [D] [E]
yuck!
Update: Adding an extra capture also works! Kudos to blokhead for this solution.
use strict; use warnings; my $re0; my $re1; $re1 = qr/ ([A-Z]) (?{ print("[$1]\n") }) /x; $re0 = qr/ () (??{ $re1 }) (??{ $re1 }) /x; 'abcDE' =~ $re0; __END__ output ====== [D] [E]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using a capture in /(?{...})/
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 |