in reply to Re: Interpolating strings within strings
in thread Interpolating strings within strings

Awesome, you guys are great. Thanks a lot.
Doug
  • Comment on Re^2: Interpolating strings within strings

Replies are listed 'Best First'.
Re^3: Interpolating strings within strings
by ikegami (Patriarch) on Sep 29, 2004 at 17:44 UTC

    If your variables are in a hash, the following doesn't compile the string at runtime. It's safer and possibly faster. I've even added an esacpe sequence (${$}) in case you need to use $!

    %vars = ( FTPPath => '/my/ftp/path', TransferMode => 'ASCII', ); s/(\$(\w+|{(\$|\w+)}))/ my $var = defined($3) ? $3 : $2; $var eq '$' ? '$' : (defined($vars{$var}) ? $vars{$var} : $1); /eg;

    Test code: