in reply to possible to evaluate scalars stored in a string?

Something like: (code tested)

use strict; use warnings; my $var1 ="a.pl"; my %hash = ( "command1" => "type $var1" ); system ($hash{"command1"});

Update:

I was thinking of adding this update, and at the same time, I saw the reply from emilford. I like this better:

use strict; use warnings; my %hash = ( "command1" => "type %s" ); my $var1 ="a.pl"; system(sprintf($hash{"command1"}, $var1));

Replies are listed 'Best First'.
Re: Re: possible to evaluate scalars stored in a string?
by emilford (Friar) on Dec 13, 2003 at 03:30 UTC
    I think this only works because $var1 is defined prior to being stored in the hash. My variables could be definied/changed anywhere in the script. I'm looking for a way to have the scalars in the hash replaced with the most current values. Thanks.