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