<?xml version="1.0" encoding="windows-1252"?>
<node id="593" title="How do I expand function calls in a string?" created="1999-10-07 20:20:52" updated="2005-08-15 08:15:26">
<type id="834">
perlfaq nodetype</type>
<author id="519">
faq_monk</author>
<data>
<field name="doctext">


&lt;P&gt;
This is documented in [perlman:perlref|the perlref manpage]. In general, this is fraught with quoting and readability problems, but it
is possible. To interpolate a subroutine call (in list context) into a
string:

&lt;P&gt;
&lt;PRE&gt;    print &amp;quot;My sub returned @{&amp;#091;mysub(1,2,3)&amp;#093;} that time.\n&amp;quot;;
&lt;/PRE&gt;
&lt;P&gt;
If you prefer scalar context, similar chicanery is also useful for
arbitrary expressions:

&lt;P&gt;
&lt;PRE&gt;    print &amp;quot;That yields ${\($n + 5)} widgets\n&amp;quot;;
&lt;/PRE&gt;
&lt;P&gt;
Version 5.004 of Perl had a bug that gave list context to the expression in &lt;CODE&gt;${...}&lt;/CODE&gt;, but this is fixed in version 5.005.

&lt;P&gt;
See also ``How can 
&lt;FONT SIZE=-1&gt;I&lt;/FONT&gt; expand variables in text strings?'' in this section of the 
&lt;FONT SIZE=-1&gt;FAQ.&lt;/FONT&gt;

&lt;P&gt;
</field>
</data>
</node>
