http://qs1969.pair.com?node_id=43154


in reply to How can one re-parse(?) a string to fill in variables

You're question is a little vague - but I'm guessing the problem is that you have code somewhat like the following (which i'll use as an example):
#!/usr/bin/perl -w use strict; my $name = 'Alex'; my $greeting = 'Hello $name!'; print $greeting;
Which you want to print 'Hello Alex', but currently it's printing 'Hello $name!'.

The following code will do this, though is perhaps a little hack-ish, and some of our more experienced monks could enlighten both of us as to a more elegant method:
#!/usr/bin/perl -w use strict; my $name = 'Alex'; my $greeting = 'Hello $name!'; $greeting =~ s|\$([\w_]+)|eval "\${$1}"|e; print $greeting;