#Create a script which takes a list of numbers from command line and
#print the same in the compact form. For example,
#if you pass “1,2,3,4,9,10,14,15,16” then it should print the compact form like “1-4,9,10,14-16”.
# perl -le '$n = $ARGV[0]; foreach(@ARGV) { if ($n++ == $_) { push @{$a[$k]},$_; } else { push @{$a[++$k]},$_; $n=$_+1} } END{ print join",", map { "$_->[0]-$_->[-1]" } @a}' 1 2 3 4 7 8 10 11 12 13
1-4,7-8,10-13
#
Аргументы должны быть уже сортированными.