- or download this
$phrase = 'Hello $dolly!';
$variables = { dolly => 'Nurse' };
- or download this
$phrase =~ s/\$([a-zA-Z0-9_]+)/$variables->{$1}/g;
# also process variables in $(var_name) format.
$phrase =~ s/\$\(([a-zA-Z0-9_]+)\)/$variables->{$1}/g;
- or download this
$phrase = '$foo $bar';
$variables = { foo => '$(bar)', bar => '$(foo)', };
- or download this
my @phrase_parts = split /(\$(?:\(\w+\)|\w+))/, $phrase;
foreach my $part ( @phrase_parts ) {
...
|| $part =~ s{ \$ \( (\w+) \) }{$variables->{$1}}xms;
}
$phrase = join '', @phrase_parts;