What is the preferred way of interpolating a constant in a here doc?
perl
Solution
Use Const::Fast instead of `Readonly` or `constant`. They interpolate without any contortions. See CPAN modules for defining constants:
For conditional compilation, constant is a good choice. It's a mature module and widely used.
...
If you want array or hash constants, or immutable rich data structures, use Const::Fast. It's a close race between that and Attribute::Constant, but Const::Fast seems maturer, and has had more releases.
On the other hand, you seem to be writing your own templating code. Don't. Instead, use something simple like HTML::Template:
use HTML::Template;
use constant FOO => 'bar';
my $tmpl = HTML::Template->new(scalarref => \ <<EOF
Foo is currently <TMPL_VAR VALUE>
EOF
);
$tmpl->param(VALUE => FOO);
print $tmpl->output;
Problem
I'm sure there are several ways of getting the value 'bar' to interpolate in the <> below, but what is the cleanest way, and why? ``` use constant FOO => 'bar'; my $msg = <<EOF; Foo is currently <whatever goes here to expand FOO> EOF ```