git.shiar.nl
/
perl
/
list-index.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
86ab995
)
more legible code to add range ends
author
Mischa POSLAWSKY
<perl@shiar.org>
Sun, 15 Nov 2009 03:43:41 +0000
(
04:43
+0100)
committer
Mischa POSLAWSKY
<perl@shiar.org>
Sun, 15 Nov 2009 03:46:51 +0000
(
04:46
+0100)
lib/List/Index.pm
patch
|
blob
|
history
diff --git
a/lib/List/Index.pm
b/lib/List/Index.pm
index e56d7713be5f5e113c7152b8a19f49e904d79b61..719aca74ed00acf60feddb2437bcce314410277f 100644
(file)
--- a/
lib/List/Index.pm
+++ b/
lib/List/Index.pm
@@
-77,12
+77,15
@@
sub ranges {
push @links, $link unless $links[-1] eq $link;
}
push @links, $link unless $links[-1] eq $link;
}
+ # add range end to each link
for my $i (0 .. $#links - 1) {
for my $i (0 .. $#links - 1) {
- my ($link, $lastchar) = $links[$i + 1] =~ /(.*)(.)/;
- $link .= $lastchar le 'a' ? '.' : chr( ord($lastchar) - 1 );
- next if $link eq $links[$i] and $i;
- $links[$i] .= '-'.$link;
+ # end at start of next value with the last character decremented
+ my $next = $links[$i + 1];
+ $next =~ s{(.)$}{ $1 le 'a' ? '.' : chr( ord($1) - 1 ) }e;
+ # amend range if it's ahead
+ $links[$i] .= '-'.$next unless $next eq $links[$i];
}
}
+ # final value takes the rest
$links[-1] .= '-';
return \@links;
$links[-1] .= '-';
return \@links;