Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: inserting HTML file in a PERL script

by Tortue (Scribe)
on May 29, 2005 at 19:04 UTC ( #461561=note: print w/replies, xml ) Need Help??


in reply to Re^2: inserting HTML file in a PERL script
in thread inserting HTML file in a PERL script

Just to generalize the script I gave you... This replaces any variable in the template with its value in the program. It's a quick-and-dirty fix that may solve your problem if you're in a rush. Of course, as others have noted, it would be better if you used a proper templating system. Note also that this only works for simple scalar variables (e.g. $thing, $ZOWIE), not for more complicated variables such as array or hash elements (e.g., $var[$num] or $var{thing}).
my $template = snarf('template.htm'); while ($template =~ /(\$[:alpha:]\w*)/g) { my $variable_name = $1; my $value = eval $variable_name; $template =~ s/\Q$variable_name\E/$value/g; } print $template;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://461561]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2022-08-14 22:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?