cvs commit: perlfaq perlfaq6.pod
[email protected] (brian d foy) 10 Aug 2005 15:55:08 -0000
| Newsgroups | perl.cvs.perlfaq |
|---|---|
| Message-ID | <[email protected]> |
cvsuser 05/08/10 08:55:08
Modified: . perlfaq6.pod
Log:
* spelling fixes
* Why does using $&, $`, or $' slow my program down?
+ Anno Siegel updated the answer for recent speed
modifications
Revision Changes Path
1.35 +15 -9 perlfaq/perlfaq6.pod
Index: perlfaq6.pod
===================================================================
RCS file: /cvs/public/perlfaq/perlfaq6.pod,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- perlfaq6.pod 6 Aug 2005 06:55:54 -0000 1.34
+++ perlfaq6.pod 10 Aug 2005 15:55:08 -0000 1.35
@@ -633,14 +633,20 @@
(contributed by Anno Siegel)
Once Perl sees that you need one of these variables anywhere in the
-program, it provides them on each and every pattern match. That means
-that on every pattern match the entire string will be copied, part of
-it to $`, part to $&, and part to $'. Thus the penalty is most severe
-with long strings and patterns that match often. Avoid $&, $', and $`
-if you can, but if you can't, once you've used them at all, use them
-at will because you've already paid the price. Remember that some
-algorithms really appreciate them. As of the 5.005 release, the $&
-variable is no longer "expensive" the way the other two are.
+program, it provides them on each and every pattern match. That means
+that on every pattern match the entire string will be copied, part of it
+to $`, part to $&, and part to $'. Thus the penalty is most severe with
+long strings and patterns that match often. Avoid $&, $', and $` if you
+can, but if you can't, once you've used them at all, use them at will
+because you've already paid the price. Remember that some algorithms
+really appreciate them. As of the 5.005 release, the $& variable is no
+longer "expensive" the way the other two are.
+
+Since Perl 5.6.1 the special variables @- and @+ can functionally replace
+$`, $& and $'. These arrays contain pointers to the beginning and end
+of each match (see perlvar for the full story), so they give you
+essentially the same information, but without the risk of excessive
+string copying.
=head2 What good is C<\G> in a regular expression?