in reply to Regexp question

"\Q" and "\E" are your friends

$tmp =~ /\Q$path\E/

Added BTW, I wonder if your $path variable is even defined all the time. Perhaps you should check for that first: $result = defined $path and $tmp =~ /\Q$path\E/;

Added xmath had a great insight that you should be using index() here instead. So that becomes (assuming $tmp is always defined as well) $result = defined $path and -1 != index $tmp, $path;.

Replies are listed 'Best First'.
Re: Re: Regexp question
by nothingmuch (Priest) on Mar 30, 2003 at 15:28 UTC
    I'd like to add: \Q and \E are a way of telling perl, within quoted text, to protect against meta characters. This is done internally by the quotemeta function. Meta characters are characters with meaning, normally beyond the seven bit ascii range.

    What \Q and \E, or quotemeta do is simply add a backslash before every character which can have a special meaning.

    An example of where this is needed is the at (@) character - it can mean an array, or just '@'. Regexes are very fragile in this sense, because many characters have a meaning.

    -nuffin
    zz zZ Z Z #!perl