diff options
Diffstat (limited to 'incdec.bash')
| -rw-r--r-- | incdec.bash | 10 | 
1 files changed, 8 insertions, 2 deletions
| diff --git a/incdec.bash b/incdec.bash index 9950f33..d00c140 100644 --- a/incdec.bash +++ b/incdec.bash @@ -58,8 +58,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;  } | 
