That much is obvious - that inside of (?{}) there is a pos() value which can be manipulated. Now is $_ a copy of the bound string or is it the actual string. See... if $_ is the actual string then stomping on pos() should work. Hmm... maybe I just answered my own question. Maybe instead of aliasing $_ which is what I thought was happening it's copying it instead.
No wait... I included a code fragment that shows that $_ is aliased to $str and that $str's pos value is being altered inside the (?{}). It looks like the regex engine is replacing the pos() value with a saved copy. So again - do you know a way to keep the regex engine from copying pos() back into place?
use Devel::Peek; $str = 'a string'; print 'x' x 50, "\n"; Dump($str); $str =~ m/(?:.(?{Dump($_);Dump(pos());pos()+=3; Dump($_);Dump(pos())}))/g; print STDERR "OUT\n"; Dump($str);
__SIG__ use B; printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE;
In reply to Re^2: immutable pos() inside regex
by diotalevi
in thread immutable pos() inside regex
by diotalevi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |