in reply to How to gracefully deal with a regex problem

I assume someplace in your code you are doing something like:
$test=~/$var/;
with $var containing some strange characters, to produce the error message? If so, simply quote the string $var ala:
$test=~/\Q$var\E/;
The quote-escape (sorry, don't know their real name) operators are extremely useful for situations like this. Check out perlop for more information.

Replies are listed 'Best First'.
Re: Re: How to gracefully deal with a regex problem
by michellem (Friar) on Mar 07, 2001 at 02:14 UTC
    Turns out, this would be great if I were just doing a test - but I'm actually doing a substitution:
    $_ =~ s/input/input value=\"$fields{$key}\"/i;
    What I'm doing is creating a way for them to edit their data - so using the \Q \E makes things hard for the end user - I'm sure they'll freak out when they are faced with a field that looks like: Job\ Announcement\ for\ March... (you get the picture.)

    I realize that the eval() idea is probably the best bet.