aboutsummaryrefslogtreecommitdiffstats
path: root/incdec.pm
diff options
context:
space:
mode:
Diffstat (limited to 'incdec.pm')
-rw-r--r--incdec.pm10
1 files changed, 8 insertions, 2 deletions
diff --git a/incdec.pm b/incdec.pm
index b53d27c..5d0783e 100644
--- a/incdec.pm
+++ b/incdec.pm
@@ -55,8 +55,14 @@ sub incdec {
}
}
- pos($line) = $start_position;
- $line =~ s/\G([^-\d]*)(-?\d+)/$1 . ($2 + $increment_by)/e;
+ # Using `\G` when `pos` is 0 seems to cause occasional missed substitutions.
+ if ($start_position > 0) {
+ pos($line) = $start_position;
+ $line =~ s/\G(-?\d+)/$1 + $increment_by/e;
+ }
+ else {
+ $line =~ s/(-?\d+)/$1 + $increment_by/e;
+ }
return $line;
}