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
Sébastien Aperghis-Tramoni
May 5, 2008 13:21
Documentation bug or brain bug? (or, what \k<name> and $+{name} refer to)
Message ID:

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  
        refer to the leftmost defined group.

and later in the "Extended Patterns" section:

                  If multiple distinct capture buffers have the same  
name then
                  the $+{NAME} will refer to the leftmost defined  
buffer in the

                  Named backreference. Similar to numeric  
                  except that the group is designated by name and not  
                  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  
                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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About