Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: inserting HTML file in a PERL script

by davidrw (Prior)
on May 29, 2005 at 15:24 UTC ( [id://461524]=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

yes, you could match on the $ and lookup the variable name in a hash, and replace with the value. Expects the template variables to be uppercase (A-Z and _ only) and the hash keys to be lower case.
use strict; use warnings; my %data = ( first_name => 'Foo', email => 'Bar', ); $/ = undef; my $s = <DATA>; $s =~ s/\$([A-Z_]+)/exists $data{lc $1}?$data{lc $1}:$&/esg; print $s; __DATA__ First name is $FIRST_NAME and<br> email is: $EMAIL. junk is $JUNK

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-19 17:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found