$lookahead = $context - $penalty;
}
- push @links, $link;
+ push @links, $link unless $links[-1] eq $link;
}
- use List::MoreUtils 'uniq';
- @links = uniq @links;
+ # add range end to each link
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;