cvs commit: perlfaq perlfaq6.pod

[email protected] (brian d foy) 27 Mar 2005 07:17:28 -0000
Newsgroups perl.cvs.perlfaq
Message-ID <[email protected]>
cvsuser     05/03/26 23:17:28

  Modified:    .        perlfaq6.pod
  Log:
  * Why does using $&, $`, or $' slow my program down?
  	+ Anno Siegel suggested fix-ups for accuracy and language
  
  Revision  Changes    Path
  1.31      +12 -11    perlfaq/perlfaq6.pod
  
  Index: perlfaq6.pod
  ===================================================================
  RCS file: /cvs/public/perlfaq/perlfaq6.pod,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- perlfaq6.pod	14 Feb 2005 18:25:48 -0000	1.30
  +++ perlfaq6.pod	27 Mar 2005 07:17:28 -0000	1.31
  @@ -1,6 +1,6 @@
   =head1 NAME
   
  -perlfaq6 - Regular Expressions ($Revision: 1.30 $, $Date: 2005/02/14 18:25:48 $)
  +perlfaq6 - Regular Expressions ($Revision: 1.31 $, $Date: 2005/03/27 07:17:28 $)
   
   =head1 DESCRIPTION
   
  @@ -630,17 +630,18 @@
   
   =head2 Why does using $&, $`, or $' slow my program down?
   
  -Once Perl sees that you need one of these variables anywhere in
  -the program, it provides them on each and every pattern match.
  -The same mechanism that handles these provides for the use of $1, $2,
  -etc., so you pay the same price for each regex that contains capturing
  -parentheses.  If you never use $&, etc., in your script, then regexes
  -I<without> capturing parentheses won't be penalized. So 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.
  +(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.
  +       
   =head2 What good is C<\G> in a regular expression?
   
   You use the C<\G> anchor to start the next match on the same