The Ghost am Montag, 16. Januar 2006 06.34: > I am storing text stings in a database. when I have the string: > > 'some perl $variable' > > which would print as: > > some perl $variable > > how can I force interpolation of '$variable'? > > one idea I thought of was: > #!/usr/bin/perl > my $var='variable'; > $string='some $var'; > $string=~s/\$(\w+)/${$1}/gi; > print "$string\n"; > > But it doesn't work. I want it to print "some variable".
One way is to change the regex a bit: #!/usr/bin/perl use strict; use warnings; my $var='variable'; my $other_var='another'; my ($string1, $string2, $string3)=map 'some $var $other_var', 1..3; # test1, test2, final version: # $string1=~s/(\$\w+)/$1/g; $string2=~s/(\$\w+)/$1/ge; $string3=~s/(\$\w+)/$1/gee; print join "\n", $string1, $string2, $string3; greetings joe -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>