Hi all.

Is there a way to insert an arithmetic calculation into a substitute
operation, keeping all "non-integers" AS THEY WERE ?

Example:
$string="blah  10      20";
I need to add 5 to the 10, and add 7 to the 20.
So after the substitution, $string will contain: "blah  15      27".
** Note - i MUST preserve the amount of <spaces> inside the string.

I tried the following:
$string =~ s/(\w+)(\s+)(\d+)(\s+)(\d+)/$1$2($3+5)$4($5+7)/;

But, it becomes: "blah  (10+5)      (20+7)".

Tried it w/out the parenthesis, with int($3+5) and with scalar($3+5).
All ended with the same result.

Any suggestions ?

Thanks,
Amit Koren.

Reply via email to