Phoenix.pm: $& discussion
Doug Miles
doug.miles at bpxinternet.com
Thu Aug 24 11:56:39 CDT 2000
Michael Dearman wrote:
>
> Hi guys,
> Enjoyed the get together and meeting you'all.
>
> Doug Miles wrote:
> >
> > I looked into the $& problem in O'reilly's "Mastering Regular
> > Expressions",
>
> For Perl ver. 5.003, don't have a clue if this still holds. The author
> has maintained an excellent support site, but I don't remember seeing
> anything addressing this issue.
>
> > and found that the inefficiency is caused by perl making a
> > copy of the string that is being matched against. This is also caused
> > by using '()'s in a regex (which I am doing), so avoiding the use of $&
>
> Just to round the culprits out - this also happens when $' and $` are used.
> As I read it, this group and parens also disable some optimizations done for
> substitutions. But for parens,this only affects the regex actually in the parens.
>
> and the /i modifier causes the copy, in some cases.
>
> Also, you'll get this performance hit if these are in any module/lib your using.
> There's a list of the offending libs on pg. 278, Mastering Reg Expressions.
> Of course some popular modules are on the list.
>
> > won't help. Also, with the addition of \s* to my pattern (which I have
>
> I'm probably missing something, but why can't you just do 'length($1)',
> for $match_length?
The reason for this is that for this tag:
<!-- date -->
length($1) would give me 4 and length($&) would give me 13, which is
what I'm looking for. I want to replace the entire tag, not just the
contents.
--
- Doug
Don't anthropomorphize computers. They hate that.
More information about the Phoenix-pm
mailing list