in reply to Re: substitution interpolation?
in thread substitution interpolation?

First off it's wrong to use qr// on rhs of s///

You must realize that the left side of s/// is the regular expression, and that the right side is merely the the substitute string ( or that which produces the substitute string)

So in effect what you are doing is:

$var =~ s/ < regex $expr > / < scalar representation of $sub > /

This is why you end up with the string (?-xism: spooge), which is the scalar value of $sub


In the node you referred to, they eval'ed the rhs one way or the other. mdillon eval'ed the rhs only ( $1 . "ar" ) by using /ee ( read perlop ), and knight eval'ed the entire perl expression ( "s/$lhs/$rhs/" ).

Replies are listed 'Best First'.
Re: Re: Re: substitution interpolation?
by h0mee (Acolyte) on May 31, 2001 at 06:43 UTC
    Thanks for pointing out my totally clueless use of qr// (was going on the advice of someone on IRC when I went down that path, instead of RTFM'ing). What I don't understand is- why does the evaling the entire expression work? Does it force interpolation of $lhs and $rhs before the expression is evaluated? In experiments,
    $_ = $var; eval "s/$lhs/$rhs/";
    works, but:
    eval "$var =~ /$lhs/$rhs/;";
    doesn't work- what am I missing?

      try this:

      eval "\$var =~ s/$lhs/$rhs/";

      update:fixed typo