in reply to Re: Variable expansion
in thread Variable expansion

I think the strings coming back are literals so what I must have is your case 1 which as you say doesn't work ! The literals contain strings that do map to local variables so somehow I've got to translate the part that is the variable to its value ? (I tried splitting it up where the '$' starts but when I set a new variable to: $newcmd=$cmd1.$cmd2; It seems to do the same thing.)

Replies are listed 'Best First'.
Re: Re: Re: Variable expansion
by broquaint (Abbot) on Apr 17, 2002 at 14:14 UTC
    If you do have the unfortunate case of having the string not being interpolated then you could use the string version of eval() to get the desired result.
    my $hr = { foo => { bar => '/dev/null' } }; my $cmd_literal = 'ls $hr->{foo}->{bar}'; my $cmd = eval qq(return "$cmd_literal";); print `$cmd`; __output__ /dev/null
    But the best option would be to have $cmd be interpolated rather than resorting to eval().
    HTH

    broquaint

      Brilliant ! That works, thankyou.. I've struggled all morning with this (in Scotland ..)