in reply to Sorting and ranging problems...

I thought that perhaps dragonchild was right and that this is most likely homework, so I decided to make my solution a learning excercise for myself as well and provide something to make you think. So I did it using regexes and turned it into golf....

I think I Tee-off at 198 chars... Which if you exclude the length of the input string is 163 (counting quotes still though)

$"=",";@0=sort{$a<=>$b}split/,/,'1089,3,4,5,6,7,99,832,1087,831,1088'; +$_= ":@0";1while s;:((\d+)(-(\d+))?),(\d+);$4?$5-$4==1?":$2-$5":",$1:$5":( +$5- $2==1)?":$2-$5":",$2:$5";e;y/:/,/d;s/^.//;print;
Oh yeah, its strict safe as well... But somehow, if this is homework, I doubt your prof's gunna like this one....

:-)

Note
I took the liberty of assuming the numbers would be unique. Oh and thanks to Chemboy for the golf language tips :-)

Yves
--
You are not ready to use symrefs unless you already know why they are bad. -- tadmc (CLPM)