in reply to [RE] match positions of named captures?

The named captures (or resulting hashes) do not have a relation to the actual position of the place where the group is defined. I think the whole intend of the module has a different purpose and I doubt the developer had group position in mind.

In the example that follows the results in this particular case foo and bar come from two different groups. How do you expect to get a position for that named group?

use strict ; use warnings ; use Data::Dumper ; my $str = "abcdef" ; $str =~ /(?<foo>[ab])*(?<bar>c)(?<foo>d)(?<bar>[ef]*)/ ; print Dumper(\%-) ;
$VAR1 = { 'foo' => [ 'b', 'd' ], 'bar' => [ 'c', 'ef' ] };

Replies are listed 'Best First'.
Re^2: [RE] match positions of named captures?
by LanX (Saint) on Dec 02, 2019 at 17:13 UTC
    > How do you expect to get a position for that named group?

    by associating a named capture to an capture index. The word tie implies that this is done somewhere.

    $VAR1 = { 'foo' => [ 'b', # $1 'd' # $3 ], 'bar' => [ 'c', # $2 'ef' # $4 ] };

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice