perl regex: replace placeholder with variable content in template -


i have template string , variables. example following:

my $template = " text <--name--> other text <--age--> ..."; $age = 15; $name = "heinz"; 

what correct regex replace template placeholder strings corresponding perl variable?

i tried

$template =~ s/<--(.*?)-->/eval('$' . lc($1))/sge; 

but not work. placeholder replaced empty string. hope has idea. in advance.

use hash,

my $template = " text <--name--> other text <--age--> ..."; %hash = (age => 15, name => "heinz");  $template =~ s/<--(.*?)-->/$hash{"\l$1"}/g; 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -