http://qs321.pair.com?node_id=626352

meshgraphics has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to slurp in an html file with $scalars. How do I get them expanded when I print out the slurp.
open OUT, "< $Outy";

{ local $/ = undef; $Slurp = <OUT>; }


print "$Slurp";

Replies are listed 'Best First'.
Re: read in file with vars
by Zaxo (Archbishop) on Jul 13, 2007 at 02:10 UTC

    It sounds like what you really want is an html template mechanism. I like Template Toolkit for that.

    You could call s/\$([a-zA-Z_]\w*)/${$1}/g on the slurped file, though you'd want to switch off warnings for that.

    After Compline,
    Zaxo

Re: read in file with vars
by dmitri (Priest) on Jul 13, 2007 at 02:21 UTC
    This should work:
    eval "print \"$Slurp\"\n"; # or print eval "\"$Slurp\"";