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

OK, I wasn't sure if there was some way to do it that was native to Perl. I will just use a standard function to modify the string. Thanks.

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

  • Comment on Re^2: Dynamic interpolation in a string with a scalar variable?

Replies are listed 'Best First'.
Re^3: Dynamic interpolation in a string with a scalar variable?
by hippo (Archbishop) on Nov 30, 2015 at 22:37 UTC
    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.

      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