Re: A Friday Regex Head Scratcher

"Jon Earle" <[email protected]>
Newsgroups gmane.user-groups.linux.ottawa.general
Message-ID <[email protected]>

Yanick Champoux wrote:

> Whereas the use of $1, $2,
> etc, will only impart a performance penalty to the regexes in which they
> are used[*], using $& will trigger that penalty for *all* regexes in the
> program (simply because there's no way to know a priori which regex we
> want to capture the content of).
>
> 	Now, this being said, that delta of performance is typically fairly
> small.  For little scripts, you'll have to squint real hard to see it.

Oh, I see... for every program (ie: .pl file), a single $& affects every
regex that could potentially be encountered in that program, whereas $1
affects only the specific regex in which it's used, in which case, Dave's
suggestion of using $1 optimizes performance of the entire program (or
rather, prevents performance degradation of the entire program).  Is that
correct?

> 	Excellent.  I was half afraid you'd take a look at the regex, turn
> green, and immediately proceed to format your hard-drive. :-)

Well, I admit, on Fri afternoon, I tried to decipher it and closed it in
fear. :)  A fresh look on Monday made it all come together.

-- 
OCLUG general discussion list
[email protected]
http://oclug.on.ca/mailman/listinfo/oclug
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.