develooper Front page | perl.perl5.porters | Postings from May 2008

Re: Documentation bug or brain bug? (or, what \k<name> and $+{name} refer to)

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
May 6, 2008 01:48
Subject:
Re: Documentation bug or brain bug? (or, what \k<name> and $+{name} refer to)
2008/5/5 Sébastien Aperghis-Tramoni <maddingue@free.fr>:
>  While writing an article (in French) about 5.10 regexps, a reviewer found
> that what I wrote about \k<name> and $+{name} was inconsistent. I reread
> perlre and perlvar, and it seems that the inconsistency lies in perlvar:
>
>  perlre/"Capture buffers" says:
>
>                                                  Outside the pattern, a
> named
>        capture buffer is available via the "%+" hash.  When different
> buffers
>        within the same pattern have the same name, $+{name} and "\k<name>"
>        refer to the leftmost defined group.
>
>  and later in the "Extended Patterns" section:
>
>        (?<NAME>pattern)
>                  [...]
>                  If multiple distinct capture buffers have the same name
> then
>                  the $+{NAME} will refer to the leftmost defined buffer in
> the
>                  match.
>                  [...]
>
>        \k<NAME>
>                  Named backreference. Similar to numeric backreferences,
>                  except that the group is designated by name and not number.
>                  If multiple groups have the same name then it refers to the
>                  leftmost defined group in the current match.
>
>  But perlvar says:
>
>        %+      Similar to @+, the %+ hash allows access to the named
>                capture buffers, should they exist, in the last successful
>                match in the currently active dynamic scope.
>
>
>  Now, if I understand correctly, perlre says that \k and %+ refers to the
> leftmost, IOW the *first* successful match, while perlvar says that %+
> refers to the *last* successful match.
>  Or am I misunderstanding something?

I think you are. The last successful match is the last =~ test that
matched successfully; the currently active dynamic scope is the
current pair of {} braces. We're not inside a regexp there.

If you find a better wording I'll be glad to apply.

Thread Previous | Thread Next


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About