From: "Uri Guttman" <[email protected]>
> >>>>> "JK" == Jenda Krynicky <[email protected]> writes:
>
> JK> From: "Joseph L. Casale" <[email protected]>
> >> Inside a here doc, how can I force an expression to be evaluated
> >> such as localtime:
>
> here docs are just a different form of string so any technique which
> works in quoted strings will work in here docs. basic here docs are
> double quoted so they will interpolate scalars and arrays.
>
> JK> use Interpolation eval => 'eval';
>
> JK> print <<"END";
>
> JK> $eval{localtime time}
> JK> Foo
> JK> Bar
>
> JK> END
>
> i would say to just use a temporary scalar variable. there is no shame
> in doing this and it is simpler than using the Interpolation module
> which is doing tied things and calling eval (which is dangerous).
Tie() yes, eval"" no. Neither the fact I called the hash eval, nor
that I told it to use the builtin interpolation named eval means
there is a string eval involved.
See the docs online, there are quite a few more builtins and you can
create your own interpolation. Eg. for formatting:
use Interpolation d => 'commify';
my $total = 54858*745;
print <<"END";
blah blah blah $d{$total}
blah blah
END
Jenda
===== [email protected] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/