in reply to (Golf) Rangify Array

3 attempts, the shortest weighing in at 77 characters(!), using japhys sort trick. I'm quite fond of the last two.

my @d=(1089,3,4,0,5,6,7,99,832,1087,831,1088,10000); print "\nfirst try\n\n"; @ary= boo(@d); print "@ary"; print "\n\nsecond try\n\n"; @ary=boo2(@d); print "@ary"; print "\n\nthird try (stringify)\n\n"; $list=boo3(@d); print $list; sub boo { # 1 2 3 4 5 6 7 + 8 9 A B C #234567890123456789012345678901234567890123456789012345678901234567890 +1234567890123456789012345678901234567890123456789012345 @_=sort{$a-$b}@_;$a[0]=$_[0];map{$q=$_[$_-1];$_[$_]==$q+1||do{$a[-1].= +"-$q";push@a,$_[$_]};$a[-2]=~s/(\d+)-\1/$1/}(1..$#_);@a } sub boo2 { # 1 2 3 4 5 6 7 + 8 #234567890123456789012345678901234567890123456789012345678901234567890 +123456789012345678 $_=join$",sort{$a-$b}@_;while(/(\d+)/g){$e=$1+1;s/($1) $e/$1-$e/;s/-\d ++-/-/}split" " } sub boo3 { # stringify # 1 2 3 4 5 6 7 + #234567890123456789012345678901234567890123456789012345678901234567890 +1234567 $_=join$",sort{$a-$b}@_;while(/(\d+)/g){$e=$1+1;s/($1) $e/$1-$e/;s/-$1 +-/-/}$_ }