addy7de has asked for the wisdom of the Perl Monks concerning the following question:
$_ = "master442arb_ba"; $rule = "master\(.*\)arb_ba"; $action = "m\$1a_ba"; s/$rule/$action/; #s/master(.*)arb_ba/"m${1}a_ba"/; print $_;
The correct output is "m442a_ba". The commented s/// command gives the correct
output but if I try the same thing with the $rule and $action variables,
it gives "m$1a_ba" as the output. Can someone explain why and what would be the correct expression?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using scalar variables as substitution regular expression
by Anonymous Monk on Apr 05, 2009 at 08:46 UTC | |
|
Re: Using scalar variables as substitution regular expression
by baxy77bax (Deacon) on Apr 05, 2009 at 08:44 UTC | |
by almut (Canon) on Apr 05, 2009 at 09:44 UTC | |
|
Re: Using scalar variables as substitution regular expression
by addy7de (Initiate) on Apr 05, 2009 at 08:35 UTC | |
by Anonymous Monk on Apr 05, 2009 at 08:49 UTC |