in reply to Invoke the Perl string interpolation engine on a string contained in a scalar variable.
my $text = 'this is my text with a <%VAR%> to interpolate'; my $vars = { 'VAR' => 'value taken from a data structure' }; $_ = $text; while ( /<%(.+?)%>/g) { #print "$1\n"; if (!defined $vars->{$1} ) { $vars->{$1} = 'undefined'; $vars->{MESSAGE} .= "$1 undefined <br />\n"; ## keep a log of mi +ssing variables } } $text =~ s/<%(.+?)%>/$vars->{$1}/g || warn("unable to substitute $1" +); print qq{$text\n};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Invoke the Perl string interpolation engine on a string contained in a scalar variable.
by AnomalousMonk (Archbishop) on Jan 19, 2019 at 23:17 UTC | |
by localshop (Monk) on Jan 22, 2019 at 01:06 UTC | |
by AnomalousMonk (Archbishop) on Jan 22, 2019 at 02:16 UTC | |
by localshop (Monk) on Jan 22, 2019 at 01:07 UTC |