in reply to A variable variable.
Actually, that does work:
bash-2.03$ perl -e'$foo = "bar"; $$foo = 1; print "$bar\n"' 1
But like so many things which work, you don't want to do it like that. You are using something called symbolic references, which although allowed by perl are dangerous if you ever let a user get near @array. For instance, they could alter the value of any other variable in your program (like $path_to_utility).
You can do something simillar using hashes:
foreach (@array) { my ($key, $val) = split(/=/, $_); $vars{$key} = $val; }
Or, if you are actually using var1, var2 etc in your program, you might just want to use an array:
foreach (@array) { next unless /var(\d+)=(.*)/; $values[$1] = $2; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 2: A variable variable.
by tilly (Archbishop) on Nov 23, 2000 at 07:01 UTC |