in reply to Double Interpolation in // operator?

Please look at your regex. When you do /$foo/, it interpolates $foo to the string '$bar'. This makes your regex try to match end-of-line ($), followed by 'bar'. That can't happen.

If $foo is '\$bar', then you have a different case. You try to match '\$', which is a literal dollar-sign, followed by 'bar'. That works.

Watch:
friday:~ $ perl -mre=debug $re = '$bar'; print map ">$_\n", grep /$re/, qw( $foo $bar ); compiling RE `$bar' size 5 first at 1 1: EOL(2) 2: EXACT <bar>(5) 5: END(0) anchored `bar' at 0 (checking anchored) minlen 3 Matching `$bar' against `bar' Setting an EVAL scope, savestack=12 1 <$> <bar> | 1: EOL friday:~ $ perl -mre=debug $re = '\$bar'; print map ">$_\n", grep /$re/, qw( $foo $bar ); compiling RE `\$bar' size 4 first at 1 1: EXACT <$bar>(4) 4: END(0) anchored `$bar' at 0 (checking anchored isall) minlen 4 >$bar


japhy -- Perl and Regex Hacker

Replies are listed 'Best First'.
Re: Re: Double Interpolation in code///code operator?
by BlueLines (Hermit) on May 24, 2001 at 23:05 UTC
    *forehead smack*

    I spent two hours last night pouring over this, and that never occured to me. ++ and thanks.

    BlueLines

    Disclaimer: This post may contain inaccurate information, be habit forming, cause atomic warfare between peaceful countries, speed up male pattern baldness, interfere with your cable reception, exile you from certain third world countries, ruin your marriage, and generally spoil your day. No batteries included, no strings attached, your mileage may vary.