diff options
Diffstat (limited to 'incdec.pm')
| -rw-r--r-- | incdec.pm | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -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; } |
