[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Easy regex?



On Sun, 20 Dec 1998 11:22:53 -0800, Robert Crews wrote:

>My hypothesis? $1 through $99 are not *backreferences*; they're just
>additional forms of those cursed match variables: They can be used
>anywhere in the Perl script, even several lines away from the regex,
>which is the damning charge against $`, $&, and $'.

No it isn't. It's the copying of a "large" amount of bytes, if your
original string is long.

>Now I'm really confused.

Note that we're having virtually the same argument on
comp.lang.perl.misc for the moment. Yes, I'm part of it. :-)

It's my feelings that the prejudice against $`, $&, and $' is a bit out
of proportion. There are indeed cases where these are worse than $1 and
friends, but it's not the general rule. It depends on:

  - how complicated the regex is. It makes no sense to make a far more
complicated regex , just to get rid of these special variables
  - how large the total string is. If you have a string of several tens
of thousands of characters, and you're matching just one character with
a regex, back references will be faster because some very large strings
are being copied to either $`or $' with every regex, even if you don't
use them. 

But, don't overreact. If you need to extract relatively large strings
anyway, it makes no sense to avoid $&, $`and $'. The hidden extra code
is simple, and should perform quite fast, in absolute terms.

	Bart.

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch