in reply to Substitutions if hash entry exists
#!/usr/bin/perl my %variables = ('$x' => 1); my $test = '$x $y'; $test =~ s/(\$\w+)/exists $variables{$1} ? $variables{$1} : $1/e; print $test, "\n"; __END__ 1 $y
Update: Every possible value is substituted (albeit by itself, if not existing as hash-key), if this is too much or discomforting, just split match and substitution...
regards,
tomte
Hlade's Law:
If you have a difficult task, give it to a lazy person --
they will find an easier way to do it.
|
|---|