First, I'll answer the question, then question the proposed code.

Double quotes do not interpolste sub calls. The need, then, is to provide a context which does. The @ and $ sigils are interpolated in qq(), so "@{something}" and "${something}" are the choices. @{[foo]} needs an array ref inside, hence the square braces. "${\foo}" also works.(foo should already be defined)

If you wish to make the call in scalar context, it is tempting to try "${\foo}" but that remains in list context. You need explicit scalar to get that.

Now to your proposed code. You are using symbolic references when there is no need at all. Is the $i suffix you are trying to use supposed to be interpolated from the loop variable for my $i (1..2) {}? Why not make an honest array of sub refs? Viz:

for (\&cut, \&paste, \&publish) { print LOG "@[[localtime]} did:", &$_,$/; }
Second, why do you need to place the calls in quotes? If you need to produce stereotyped strings, @strings = map sprintf is to be preferred.

Update; fixed typo in code, clarified function name scope issue.

After Compline,
Zaxo


In reply to Re: call sub in string by Zaxo
in thread call sub in string by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.