Gabriel Striewe wrote:

I wanted to interpolate a function reference in a here doc.
The following works fine:

my $hello = sub {
                 return "hello world!";
                };

printf "hello $s\n", &$hello();

But when I use a heredoc instead, it doesn't work:

print <<END;
hello &$hello()
END

At least it does not properly dereference this function
reference.

What do I do wrong?

First of all, the ampersand subroutine designation is outdated and dangerous
and it is far better to use the indirect notation for a subroutine call:

$hello->()

Perl will interpolate only simple variables or array or hash elements
or slices. However we can cheat by putting the result of the call into
an anonymous array and then dereferencing it:

print <<END;
hello @{[$hello->()]}
END


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to