if (/(\$[^\/\n\t]*)/) {
What if the presumed variable is $f.`rm -rf $ENV{HOME}`? Oops. Lotsa space now..
my $var = $&; my $key = $var; substr($key, 0, 1) = "";
You capture your match with () and then use $&? And what do you have $var for? Why not $key = $1?
Leave the the $ out of your capturing parens. That way you haven't got to strip it with substr.
I'd write your loop as
while(<FILE>) { if (my ($key) = /\$(\w+)/) { defined($ENV{$key}) and s/\$$key/$ENV{$key}/ or $undefinedVars++; } print; }
but it's usefulness depends on the input file...
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
In reply to Re: Replacing environment variables
by shmem
in thread Replacing environment variables
by loris
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |