opensource has asked for the wisdom of the Perl Monks concerning the following question:

if($file=~/$pattern/){...} In the above code, the variable doesn't seem to be interpolated before passing it to the regex engine. How do I go about, if I have the pattern changing. Thanks.

Replies are listed 'Best First'.
Re: Interpolation
by Zaxo (Archbishop) on Sep 25, 2002 at 01:56 UTC

    It does interpolate. I suspect you have path seperators in a pattern to match a variable called $file, and they are becoming an unexpected part of the regex. Fix that by using quotemeta or else the \Q \E metapair in the regex:  if($file=~/\Q$pattern\E/){...}

    After Compline,
    Zaxo