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"
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|