in reply to condense list of numbers to ranges

I'm actually proud of this one:

@numbers = (1,2,3,4,8,9,10,13,14,18,19,20,24); for(@numbers) { push @$range,$_ and next if $range and $_-$range->[-1]==1; push @ranges, ($range = [$_]); } $rangelist = join(',', map { @$_>2 ? "$_->[0]-$_->[-1]" : @$_ } @ranges ); print "($rangelist)";

The for-loop builds an array of arrays, where each subarray is a sequence on consecutive numbers. The join/map turns the bigger subarrays into the '-' notation.

Happy coding!

Update: Yes, I agree, the regex is cooler... I still like mine though!