I have some constants (defined with `use constant`) that I am desirous of using in a `here` doc. However no interpolation occurs, so the strings naming the constants literally appear instead of their values.
What I have resorted to is: assigning variables the values of the constants, and using the variable names in the here doc. Is there a better way to accomplish the desired behavior?
use constant {
OUT_DIR => 'out',
OUT_FIELDSEP => '=',
OUT_FILENAME => 'ks',
OUT_SUFXSTOR => 'storable',
VAL_MIN => 15,
VAL_MAX => 3600,
};
This does not work as intended:
print <<USAGE;
This program does this and that with the OUT_DIR. The filename is
OUT_FILENAME and the file suffix is OUT_SUFXSTOR.
Fields are separated with the OUT_FIELDSEP character. Enter a value
between VAL_MIN and VAL_MAX.
USAGE
What I've resort to doing:
my $out_dir = OUT_DIR;
my $out_fs = OUT_FIELDSEP;
my $out_fn = OUT_FILENAME;
my $out_sx = OUT_SUFXSTOR;
my $valmin = VAL_MIN;
my $valmax = VAL_MAX;
print <<USAGE;
This program does this and that with the $out_dir. The filename is
$out_fn and the file suffix is $out_sx.
Fields are separated with the $out_fs character. Enter a value
between $valmin and $valmax.
USAGE
Searched for donuts and crumpit. Found content instead.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.