Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

read in file with vars

by meshgraphics (Initiate)
on Jul 13, 2007 at 01:51 UTC ( #626352=perlquestion: print w/replies, xml ) Need Help??

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,

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\"";

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://626352]
Approved by dmitri
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2021-04-22 15:26 GMT
Find Nodes?
    Voting Booth?

    No recent polls found