john john - 27 days ago 5
Perl Question

perl regex, replace each individual words with another one

I have a formulat like

(var1 - var2 ) + var3


I want to replace
var1 - var 3
with

(put(var1,format.) - put(var2, format.) + put(var3, format.)


what is the simplest way to do that with perl reg?

thanks.

Answer
$string = '(var1 - var2 ) + var3';
$string  =~ s/\b(var\d+)\b/put($1, format.)/g;
print $string;
Comments