@@ -261,12 +261,26 @@ sub compress_inner
261
261
}
262
262
263
263
#
264
- # Return the zeropadding, if any, of $n:
264
+ # Return the zeropadded width of $n, where the zero-padded
265
+ # width is the minimum format width a number with the given
266
+ # zero-padding. That is, no zero-padding is 1, because 0-9
267
+ # have a minimum width of 1, "01" has a width of 2, 010 has
268
+ # a width of 3 and so on.
265
269
#
266
- sub zeropadding
270
+ sub zeropadwidth
267
271
{
268
272
my ($n ) = @_ ;
269
- return (($n =~ / ^0/ ) and ($n ne " 0" )) ? length $n : 0;
273
+
274
+ #
275
+ # zeropad width is the length of $n if there are any leading
276
+ # zeros and the number is not zero itself.
277
+ #
278
+ return length $n if (($n =~ / ^0/ ) and ($n ne " 0" ));
279
+
280
+ #
281
+ # If no leading zeros (or $n == 0) then the width is always '1'
282
+ #
283
+ return 1;
270
284
}
271
285
272
286
sub comp
@@ -281,7 +295,7 @@ sub comp
281
295
282
296
for my $host (sortn (@_ )) {
283
297
my ($p , $n ) = $host =~ / (.*?)(\d *)$ / ;
284
- my $zp = &zeropadding ($n );
298
+ my $zp = &zeropadwidth ($n );
285
299
#
286
300
# $s{$p} is a reference to an array of arrays
287
301
# that indicate individual range elements of
@@ -292,9 +306,21 @@ sub comp
292
306
# with zero-padding $zp into the @{$s{$p}} array.
293
307
294
308
#
295
- # See if $n-1 exists in the $s{$p} array (with same zero-pad)
309
+ # Need to check if $n-1 exists in the $s{$p} array, but the
310
+ # zero-padded width must be compatible. e.g.. "9" and "09"
311
+ # are compatible with 10, but not with 010.
296
312
#
297
313
my $idx = $i {$p }{$zp }{$n -1};
314
+
315
+ #
316
+ # If the current zeropad is 1, and the length of $n is > 1,
317
+ # then we check for a previous number with either zp == 1 or
318
+ # zp == length. This catches 09-10, 099-100, etc .
319
+ #
320
+ if (!defined $idx && $zp == 1) {
321
+ $idx = $i {$p }{length $n }{$n -1};
322
+ }
323
+
298
324
if (defined $idx ) {
299
325
#
300
326
# $n - 1 is already in array, so update END:
0 commit comments