Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: inserting HTML file in a PERL script

by Tortue (Scribe)
on May 29, 2005 at 19:04 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-16 06:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found