Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Calling a function from within a HERE doc?

by bart (Canon)
on Aug 17, 2005 at 19:06 UTC ( [id://484537]=note: print w/replies, xml ) Need Help??


in reply to Calling a function from within a HERE doc?

You can do this, as well as interpolation in more normal double-quoted strings, with the module Interpolation, originally written by dominus as a joke, currently maintained by Jenda.

I don't like the import interface, I think you should just call a tie a tie, but you can just use tie with the module without any changes.

use Interpolation; tie my %EVAL, Interpolation => 'eval'; # or: tie my %EVAL, Interpolation => sub { shift }; print <<"END"; The sum of 3 and 4 is $EVAL{3+4}. END
(Be sure to have at least one more line under "END")

The key to how this works is that an index to a hash or an array is always interpreted as perl code. Next, a tied hash is used to execute an associated function, instead of actually fetching a hash value out of somewhere.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://484537]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-24 09:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found