CUFP
japhy
snippet
<div class="Description">Converts a list of numbers to a string of ranges: (1,2,3,5,8,9,10,11) to "1-3,5,8-11".</div>
<CODE>
use 5.6.0; # for (??{ ... })
sub num2range {
local $_ = join ',' => sort { $a <=> $b } @_;
s/(?<!\d)(\d+)(?:,((??{$++1})))+(?!\d)/$1-$+/g;
return $_;
}
</CODE>