http://www.perlmonks.org?node_id=1027777

Doctrin has asked for the wisdom of the Perl Monks concerning the following question:

Hello dear Monks. Say, I have a sorted list like this: 1,2,3,4,9,16,22,23,24,30,35 I want to transform it to: 1-4,9,16,22-24,30,35 So that ranges of numbers are spelled as ranges, not as lists. I know how to solve the inverse problem:
use Set::IntSpan; my $span = Set::IntSpan->new('1-4,9,16,22-24,30,35'); print join "," => $span->elements();
would give me 1,2,3,4,9,16,22,23,24,30,35 . Is there a way to make ranges from a list? Maybe, modules similar to Set::IntSpan, or some algorithm?.. Thanks in advance.