Re: Making thunderbird attachments searchable

[email protected] (Vlado Keselj) Wed, 6 Jan 2010 08:50:13 -0400 (AST)
Newsgroups perl.scripts
Message-ID <[email protected]>

On Wed, 6 Jan 2010, Johan Vromans wrote:

...
> >                 if (/$partbody_boundary/) {
> 
> The variable may contain characters that have a special meaning when
> used inside a pattern.
> 
> You can use either:
> 
>         $partbody_boundary = quotemeta($partbody_boundary);
>         if ( /$partbody_boundary/ )
> 
> or
> 
>         if ( /\Q$partbody_boundary\E/ )
> 
> This will 'quote' the potential special characters so they only match
> themselves.

Or, probably better, just use:
if ( index($_,$partbody_boundary) >= $[ )

One would expect index to be faster, eventhough regex are likely 
sufficiently optimized, but we also save on transforming the string with 
\Q, and compiling it as an regex.

--Vlado