note
pc88mxer
For your first question:
<c>
sub prog_replace_string {
my ($replace_this, $with_this, $string) = @_;
$string =~ s{\Q$replace_this\E}{$with_this}g;
$string;
}
</c>
For your second:
<c>
sub replace_vars {
my ($string, $hash) = @_;
$string =~ s{\$(\w+)}{$$hash{$1}}ge;
$string;
}
my %vars = ( a => 1, b => 22, c => 333 );
print replace_vars('a: $a, b: $b, c: $c', \%vars);
</c>
702515
702515