What you need is eval, BUT 'command $foo' is unlikely to be valid perl so the eval will fail. This regex method works because we capture the scalar and perform the required (double) eval (first eval gets you $var out of $1, second gets you 'value' out of $var). You may wish to add more than \w in the capture after the $ for things like $foo->{bar} if you are getting that weird.
This is almost certainly a bad way to do it BTW.%hash = ( 'command' => 'command_name -n $var1 -p $var2' ); $var1 = 'foo'; $var2 = 'bar'; $command = $hash{'command'}; $command =~ s/(\$\w+)/$1/gee; print $command; # system ($command); __DATA__ command_name -n foo -p bar
cheers
tachyon
In reply to Re: Re: Re: possible to evaluate scalars stored in a string?
by tachyon
in thread possible to evaluate scalars stored in a string?
by emilford
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |