summaryrefslogtreecommitdiff
path: root/pod/perlvar.pod
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2018-08-19 13:55:30 +0100
committerDavid Mitchell <davem@iabyn.com>2018-08-26 20:57:34 +0100
commit0b9dad94ed37e484db3e29d315fc26305c88f250 (patch)
treea48a5a82813b42d1688de0c2956cffa59e99c277 /pod/perlvar.pod
parentbefca383a461d1ce6deea75d7e0c73084408db3d (diff)
downloadperl-0b9dad94ed37e484db3e29d315fc26305c88f250.tar.gz
Improve docs for lastparen, lastcloseparen
There's lots of confusion here, especially about lastparen - some of the docs are just plain wrong.
Diffstat (limited to 'pod/perlvar.pod')
-rw-r--r--pod/perlvar.pod15
1 files changed, 13 insertions, 2 deletions
diff --git a/pod/perlvar.pod b/pod/perlvar.pod
index c7b77120ef..114a7e0d12 100644
--- a/pod/perlvar.pod
+++ b/pod/perlvar.pod
@@ -1046,7 +1046,10 @@ This variable is read-only and dynamically-scoped.
=item $+
X<$+> X<$LAST_PAREN_MATCH>
-The text matched by the last bracket of the last successful search pattern.
+The text matched by the highest used capture group of the last
+successful search pattern. It is logically equivalent to the highest
+numbered capture variable (C<$1>, C<$2>, ...) which has a defined value.
+
This is useful if you don't know which one of a set of alternative patterns
matched. For example:
@@ -1063,7 +1066,15 @@ X<$^N> X<$LAST_SUBMATCH_RESULT>
The text matched by the used group most-recently closed (i.e. the group
with the rightmost closing parenthesis) of the last successful search
-pattern.
+pattern. This is subtly different from C<$+>. For example in
+
+ "ab" =~ /^((.)(.))$/
+
+we have
+
+ $1,$^N have the value "ab"
+ $2 has the value "a"
+ $3,$+ have the value "b"
This is primarily used inside C<(?{...})> blocks for examining text
recently matched. For example, to effectively capture text to a variable