develooper Front page | perl.perl5.porters | Postings from March 2007

Re: $& in diagnostics.pm

Thread Previous | Thread Next
From:
Abigail
Date:
March 15, 2007 09:44
Subject:
Re: $& in diagnostics.pm
Message ID:
20070315164413.GE14610@abigail.nl
On Thu, Mar 15, 2007 at 05:33:29PM +0100, Rafael Garcia-Suarez wrote:
> On 15/03/07, Andy Lester <andy@petdance.com> wrote:
> >
> >Surprising problem of the day: We set up our test bot to run with -
> >Mdiagnostics, and performance went in the toilet, and some of our
> >tests that make sure indexing happens within a reasonable amount of
> >time actually failed.
> >
> >Why?  because diagnostics.pm uses $& and $', which makes all our
> >regex-based code go sloooow, especially KinoSearch.
> 
> Apparently only $&, and only once, in blead at least.

Yeah, that's what I found as well.

> 
> >Anyone feel like modifying diagnostics.pm to remove those?  It seems
> >like the Right Thing To Do.  Otherwise, I will and submit a patch
> >tomorrow or next week.
> 
> Ooh look a real-world test for a blead feature.
> 
> Could you try this ?
> 
> ==== //depot/perl/lib/diagnostics.pm#41 -
> /home/rafael/p4blead/lib/diagnostics.pm ====
> --- /tmp/tmp.22268.66   2007-03-15 17:32:24.000000000 +0100
> +++ /home/rafael/p4blead/lib/diagnostics.pm     2007-03-15
> 17:31:13.000000000 +0100
> @@ -394,7 +394,7 @@ my %msg;
>                         $toks[$i] = '[\da-f]+';
>                    }
>                 } elsif( length( $toks[$i] ) ){
> -                    $toks[$i] =~ s/^.*$/\Q$&\E/;
> +                    $toks[$i] =~ s/^.*$/\Q${^MATCH}\E/p;
>                     $conlen += length( $toks[$i] );
>                 }
>             }
> 
> (The backwards-compatible equivalent is left as an exercise to the 
> reader...)

My suggestion would be:

    $toks[$i] =~ s/^(.*)$/\Q$1\E/;

But I don't see a reason why it cannot be:

    $toks[$i] = quotemeta $toks[$i];


Abigail


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About