I am currently using this code to replace $a and $b variables from a template. However I need to make this more dynamic so I do not need to specify the values any more.
sub prog_replace_string {
my $replace_this = shift;
my $with_this = shift;
my $string = shift;
my $length = length($string);
my $target = length($replace_this);
for(my $i=0; $i<$length - $target + 1; $i++) {
if(substr($string,$i,$target) eq $replace_this) {
$string = substr($string,0,$i) . $with_this . substr($stri
+ng,$i+$target);
}
}
return $string;
}
I was wondering how to do replace certain denoted names dynamically in a template file, such as in this context:
<b><u><i>$var</i></u></b>
and replacing this with the value of $var.
I would think this would be possible by using a reference to the regexp match in a regexp like:
$string = s/\$XXXXXXXX/${$1}/;
Of course this does not work, I do not know what to replace XXXXXXXX with and the $1 variable would return the entire variable name, however we need it without the $ sign.
This must be really easy. I would love if someone could help me out without pointing to the use of a module.
Thanks a lot!