in reply to substitution interpolation?

Do it this way

tachyon

my $var = "my dog spot"; my $expr = "(my dog) spot"; $var =~ m/$expr/; my $sub = "$1 spooge"; $var =~ s/$expr/$sub/; print $var;

By matching first we define $1. When we define $sub $1 is interpolated into the string. We then do the substitution with the replacement string fully formed, and ta da - it works

Cheers

Replies are listed 'Best First'.
Re: Re: substitution interpolation?
by sierrathedog04 (Hermit) on May 31, 2001 at 13:46 UTC
    If I may make a minor comment, I don't think it is a good idea to call a scalar $sub. When I was reading the code my eye missed the '$' and I thought that you were doing something unusual to a subroutine.

    If you just called the scalar $subst the initial confusion would go away.