Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Interpolating strings within strings

by Darby (Sexton)
on Sep 29, 2004 at 16:47 UTC ( [id://395057]=note: print w/replies, xml ) Need Help??


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:

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://395057]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-16 04:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found