Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2021-04-21 06:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?