in reply to condense list of numbers to ranges

This was question #6 of the Perl Quiz of the Week. If you want some different ways to solve this one, look at the solutions that the list members came up with, or look at MJD's summary of the quiz.

The one from Andreas Koenig was probably the shortest and easiest of the solutions:

use Set::IntSpan; # CPAN rules :-) use strict; sub format_number_list { my(@n) = @_; my $set = Set::IntSpan->new(join ",", @n); my $run = $set->run_list; $run =~ s/,/, /g; # give them the spaces $run; }