J. Alejandro Ceballos Z. wrote:
> How may I avoid partial interpolation over a pattern sustitution?
> 
> My code looks like:
> 
>      # searching for all matches for later use
>      @matches = $htmlpage =~ m/<pre>(.*?)<\/pre>/gs;
>      for ($i=0; $i<$#matches; $i++)
>        { $htmlpage =~ s/<pre>$matches[$i]<\/pre>/<predefined:$i\/>/; }
> 
> 
> The problem comes when the matches contains regex characters, and
> they try to be evaluated (ex. '|+--..' must be interpeted like
> '\|\+--\.\.'). 

You can use the following prior to entering the for loop.

   $_ = quotemeta($_) for @matches;

You could also combine the capturing and substitution something like this:

   my @matches;
   $htmlpage =~ s/<pre>(.*?)<\/pre>/push(@matches, $1) &&
"<predefined:$#matches>"/geis;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to