in reply to Re^2: Dynamic interpolation in a string with a scalar variable?
in thread Dynamic interpolation in a string with a scalar variable?

some way to do it that was native to Perl.

The "native" way: with a closure:

my $variable = 3; my $string = sub { return "Variable: $variable\n"; }; print &$string; $variable = 4; print &$string;

I assume here that by "native" you mean "without using a module". However, be advised that many modules are written using "native" pure perl and that modules are as much a part of the language as the print function.

Replies are listed 'Best First'.
Re^4: Dynamic interpolation in a string with a scalar variable?
by nysus (Parson) on Dec 01, 2015 at 00:48 UTC
    Nice, thanks. Yeah, instead of "native," "built-in" would have been more accurate.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon";
    $nysus = $PM . $MCF;
    Click here if you love Perl Monks