in reply to How to find a number and replace it with calculated value?
use warnings; use strict; while (<DATA>) { s/(Z=)(\d+)/$1 . $2*4/eg; my $i = 1; s/\b(XP)\b/$1 . ' (' . $i++ . ')'/eg; print; } __DATA__ Z=1 Z=2 Z=3 foo XP bar XP boo
Outputs:
Z=4 Z=8 Z=12 foo XP (1) bar XP (2) boo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to find a number and replace it with calculated value?
by Lejocode (Novice) on Mar 03, 2017 at 13:33 UTC | |
by AnomalousMonk (Archbishop) on Mar 03, 2017 at 21:20 UTC | |
by Lejocode (Novice) on Mar 03, 2017 at 21:36 UTC |