note
pemungkah
The cheap but punctuation-heavy answer:
<code>
my $string = "this is an interpolated method call: @{[$obj->method]}";
</code>
What's happening here, working from the inside out:
<ol>
<li> The method call happens, and it returns a list of zero or more values.
<li>Outside that, we have an anonymous array constructor, so now we've got a reference to an anonymous array containing the value(s) returned from the method.
<li>Outside that, we have <tt>@{ }</tt>, which dereferences the array reference, so we have an array.
<li>Perl now happily interpolates the dynamically-generated anonymous array into the string, because it knows how to do that.
</ol>
This is essentially what Interpolation.pm does, cut down to adding a few extra characters in your string. Drawback: ugly, and possibly really confusing to the reader. Advantage: only 5 extra characters.
17466
17466