summaryrefslogtreecommitdiff
path: root/pod/perlre.pod
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2006-11-22 18:11:02 +0100
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2006-11-22 17:09:33 +0000
commit58e23c8d7d24dd08c87b5d56819ad45527176c15 (patch)
tree1ed907b4695e2e09aa8e20c637acf4ac4ac1c1f3 /pod/perlre.pod
parentb775e6bae012223b0a5cf674d4a41f12f635fb75 (diff)
downloadperl-58e23c8d7d24dd08c87b5d56819ad45527176c15.tar.gz
\G with /g results in infinite loop in 5.6 and later
Message-ID: <9b18b3110611220811k1a54f650t1bd7c6a9450b0a7e@mail.gmail.com> p4raw-id: //depot/perl@29354
Diffstat (limited to 'pod/perlre.pod')
-rw-r--r--pod/perlre.pod22
1 files changed, 17 insertions, 5 deletions
diff --git a/pod/perlre.pod b/pod/perlre.pod
index 7df564738e..c1cc75d13c 100644
--- a/pod/perlre.pod
+++ b/pod/perlre.pod
@@ -443,13 +443,25 @@ It is also useful when writing C<lex>-like scanners, when you have
several patterns that you want to match against consequent substrings
of your string, see the previous reference. The actual location
where C<\G> will match can also be influenced by using C<pos()> as
-an lvalue: see L<perlfunc/pos>. Currently C<\G> is only fully
-supported when anchored to the start of the pattern; while it
-is permitted to use it elsewhere, as in C</(?<=\G..)./g>, some
-such uses (C</.\G/g>, for example) currently cause problems, and
-it is recommended that you avoid such usage for now.
+an lvalue: see L<perlfunc/pos>. Note that the rule for zero-length
+matches is modified somewhat, in that contents to the left of C<\G> is
+not counted when determining the length of the match. Thus the following
+will not match forever:
X<\G>
+ $str = 'ABC';
+ pos($str) = 1;
+ while (/.\G/g) {
+ print $&;
+ }
+
+It will print 'A' and then terminate, as it considers the match to
+be zero-width, and thus will not match at the same position twice in a
+row.
+
+It is worth noting that C<\G> improperly used can result in an infinite
+loop. Take care when using patterns that include C<\G> in an alternation.
+
=head3 Capture buffers
The bracketing construct C<( ... )> creates capture buffers. To