##   Nobumi Iyanaga wrote:

##   > I found some minor problems
##   (concerning double values.)
##
##  Solution:

my @list=(343, 512, 71, 562, 346, 345, 513, 561, 563, 343, 513, 549, 562,
71, 76, 345, 510, 563);

for (@list)  {
  $List{$_}++ }

my $string = join ", ",sort {$a<=>$b} keys %List;
$string =~ s/(\d+), (?=(\d+))/($2-$1==1)?"$1-":"$1, "/eg;
$string =~ s/(-\d+)+/$1/g;
print $string, "\n";


##  Comment:
##  A hash
##      %List    ## (that is a not-sorted list of key+value-pairs)
##  is a good means to gather in all double key occurences.
## Then only use the keys of that hash.

##  It was a good idea of yours to supply comprehensive test data;
##  and these are the results:

##  before: 71, 71, 76, 343, 343, 345, 345-346, 510, 512-513, 513, 549, 561-562, 
562-563, 563
##  after : 71,     76, 343,           345-346, 510, 512-513,      549, 561-563

##  HTH, Detlef

Reply via email to