Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I interpolate the result of a function in a Perl here doc?

Tags:

perl

I was wondering if it was possible to call a function inside a Perl here doc

sub Function
{
}

print<<HERE;

  Function()

HERE
like image 429
Zerobu Avatar asked Mar 11 '10 02:03

Zerobu


1 Answers

Do you mean that you want the function's return value to be interpolated into the heredoc?

sub Function {
    qw( Hello, World! );
}

print <<HERE;

  @{[ Function() ]}

HERE

To explain the syntax, perlmonks says:

The @{} interpolates an array into your here-doc, and the inner [] creates an anonymous array, whose elements consist of whatever expression(s) you want to put between them.

like image 135
ephemient Avatar answered Oct 21 '22 07:10

ephemient