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

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

Thread Next
From:
Sébastien Aperghis-Tramoni
Date:
May 5, 2008 13:21
Subject:
Documentation bug or brain bug? (or, what \k<name> and $+{name} refer to)
Message ID:
A9CBB86B-3143-4531-ABD8-88AB9007FD6E@free.fr
Hello,


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?


-- 
Sébastien Aperghis-Tramoni

Close the world, txEn eht nepO.


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About