in reply to Interpolating strings within strings

while (my $command = $ftpgizmo->next_ftp_command ) { print OUT eval qq{"$command\n"}; }

Replies are listed 'Best First'.
Re^2: Interpolating strings within strings
by Darby (Sexton) on Sep 29, 2004 at 16:47 UTC
    Awesome, you guys are great. Thanks a lot.
    Doug

      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: