in reply to Problems with matching and metacharacters

Simply put \Q and \E around $input. Like so:
 m/(\Q$input\E)/

Don't do this:
m/\Q($input)\E/
Because the regex will also try to match the parenthesis.

Sarah
Update: I never said I was fast.

Replies are listed 'Best First'.
Re: Re: Problems with matching and metacharacters
by Anonymous Monk on Jun 14, 2001 at 19:55 UTC
    Actually, the \E is not needed, since $input is the only thing in the regex; that is, it is automatically ended.
    /(\Q$input)/
    Here's a question: Why would you need to put parentheses around $input? You can access its value more efficiently as $input, than as $1, since parentheses would slow down the regex. More succintly, change the code to this:
    /\Q$input/
    And change occurences of $1 to $input

      Actually, /(\Q$input)/ produces the error:

      /(\(\)/: unmatched () in regexp

      because you're now matching $input), not just $input. If the parenthesis are to stay, you'll need the \E

      Sarah