<?xml version="1.0" encoding="windows-1252"?>
<node id="12275" title="Double Interpolation of a String" created="2000-05-18 00:45:17" updated="2005-08-15 03:06:39">
<type id="1980">
snippet</type>
<author id="1382">
chromatic</author>
<data>
<field name="doctext">
</field>
<field name="snippetdesc">
Suppose you have a string with variable names in it.  You want them to be expanded when you print it, but you're not sure how.  Never fear, you can abuse [eval]()!
</field>
<field name="snippetcode">
&lt;CODE&gt;my $color = "red";
my $fruit = "apple";
my $name = "chromatic";

my $string = 'Hi, my name is $name.  Please hand me a $color $fruit.';
print "&gt;&gt;$string&lt;&lt;\n";	# demonstrate what we have

my $s2;
eval "\$s2 = qq/$string/";	# the real magic
print "-&gt;$s2&lt;-\n";	# demonstrate the result&lt;/CODE&gt;</field>
</data>
</node>
