William Lewis Brown wrote: > Hi, > I have a need to store replacement text for a regex > substitution in a variable. In other words, I have code in a perl > script like so:: > > $foo =~ s/(.*)bar(.*)/$replacement/g; > > The $replacement string needs to contain a "reference" to $1. In > other words, the string $replacement will contain the string "$1". I > need to have the $1 string interpreted so that it will be replaced > with the text of the first '(.*)' expression. I have not yet found a > way to get this to happen. The "$1" string always seems to be > interpreted as a plain string.
You need to use eval and /e $foo =~ s/(.*)bar(.*)/eval $replacement/ge; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>