in reply to s/// ignoring subexpressions with variable replacement patterns
Works. But you'd better be very careful about what replacement strings are entered!$oldpat = '-([0-9]+)-'; $newpat = '"_$1_"'; # note double quotes in single quotes $newname = $oldname; $newname =~ s/$oldpat/$newpat/ee; # note double ee
It will eval '"_$1_"' to mean "_$1_" and then replace the match with what that expression (not string) returns.
Anyway, contrary to what mattriff said, just putting the $newpat in double quotes will interpolate $1 before the match is run, so that won't work.
-- Joost downtime n. The period during which a system is error-free and immune from user input.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: s/// ignoring subexpressions with variable replacement patterns
by mattriff (Chaplain) on Oct 04, 2002 at 16:58 UTC |