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
Post a Comment