From e256e34a9ccd735aca45a8e42d284b297e094b8f Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 15 Aug 2021 20:02:42 +0200 Subject: incdec: Add comments describing the middle-of-number handling loop --- incdec.pm | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'incdec.pm') diff --git a/incdec.pm b/incdec.pm index a400f7f..927ba92 100644 --- a/incdec.pm +++ b/incdec.pm @@ -17,13 +17,21 @@ sub incdec { my $line_part = $line; while ($point_position < length($line_part)) { $line_part =~ /(\d+)/; + + # If `$point_position` is within the matched number, we can stop. if ($-[0] <= $point_position && $point_position < $+[0]) { last; } + # Continue the loop if point is further right than the end of the match. if ($point_position >= $+[0]) { + # Store the line part that we don't increment so we can include it at the end. $line_start .= substr($line_part, 0, $+[0]); + + # Match starting in the next part of the string next iteration. $line_part = substr($line_part, $+[0]); + + # Adjust point position according to the new line part. $point_position -= $+[0]; next; -- cgit v1.2.3