http://qs1969.pair.com?node_id=115161


in reply to Re: (Golf) Rangify Array
in thread (Golf) Rangify Array

You don't need to make that a non-capturing parenthesis, nor resort to lookahead/lookbehind trickery; a simple word boundary will do. Very nice trick with $+, though ;)
# 27 + 40 + 2 = 69 dude! sub num2range { #234567890123456789012345678901234567890 my$x=join',',sort{$a-$b}@_; $x=~s/\b(\d+)(,((??{$++1})))+\b/$1-$+/g; $x }