in reply to How to evaluate a variable in a text string
The strict-compliant (recommended) way:$val = '123'; while (<DATA>) { s/\$(\w+)/$$1/g; print; } __DATA__ test_string_$val
Please read Why it's stupid to use a variable as a variable nameuse strict; use warnings; my %subs = (val => '123'); while (<DATA>) { s/\$(\w+)/$subs{$1}/g; print; } __DATA__ test_string_$val
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to evaluate a variable in a text string
by tariqahsan (Beadle) on Mar 28, 2005 at 21:12 UTC |