in reply to Dynamic interpolation in a string with a scalar variable?

This is a common question. Use a templating system (see Template) or String::Interpolate.
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Dynamic interpolation in a string with a scalar variable?
by nysus (Parson) on Nov 30, 2015 at 21:08 UTC
    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

      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