Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Global match and capture group in look-ahead == under-populated "@-"? (updated)

by LanX (Saint)
on Nov 19, 2022 at 14:19 UTC ( [id://11148257]=note: print w/replies, xml ) Need Help??


in reply to Global match and capture group in look-ahead == under-populated "@-"?

https://perldoc.perl.org/perlvar#@-

    $-[0] is the offset of the start of the last successful match. $-[n] is the offset of the start of the substring matched by n-th subpattern, or undef if the subpattern did not match.

edit

It's hard to tell which result you expect, but the way pos is changed after replacing a zero length assertion is tricky. It's meant to avoid endless loops.

use v5.12; use warnings; use Data::Dump 'dd'; $_ = 'aa'; s/(?=(a))(?{say "\$1='$1' \@-=(@-) pos=",pos})/b/g; dd [$1]; dd \@-; dd $_; __END__ $1='a' @-=(0 0) pos=0 $1='a' @-=(0 0) pos=0 $1='a' @-=(1 1) pos=1 $1='a' @-=(1 1) pos=1 ["a"] [1] "baba"

update

this may shed some light

use v5.12; use warnings; use Data::Dump 'dd'; $_ = 'ab'; s/(?=([ab]))(?{say "\$1='$1' \@-=(@-) pos=",pos})/X/g; dd [$1]; dd \@-; dd $_; __END__ $1='a' @-=(0 0) pos=0 $1='a' @-=(0 0) pos=0 $1='b' @-=(1 1) pos=1 $1='b' @-=(1 1) pos=1 ["b"] [1, 1] "XaXb"

Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11148257]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-26 02:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found