GöTz Verdieck wrote:
> Hi,
> I'm looking for a solution for the following problem:
>
> This is the list I have : $kommalist ="20,21,22,23,24,25,27,28,31,32,33";
>
> And I want to convert it into : $newlist ="20..25,27,28,31..33";
>
> So, I only want to combine the elements if there are more than two like
> 20,21,23
assume your list is in order as you specify, try:
#!/usr/bin/perl -w
use strict;
my ($s,$n) = '0,1,2,3,4,5,8,9,20,21,22,23,24,25,27,28,31,32,33','';
while($s =~ s/\d+//){
my $o = my $t = $&;
$t = $1 while($s =~ s/,(@{[$t+1]})(?=,|\z)//);
$n .= $t - $o > 1 ? "$o..$t," : $t == $o ? "$t," : "$o,$t,";
}
substr($n,-1)='';
print $n,"\n";
__END__
prints:
0..5,8,9,20..25,27,28,31..33
david
--
$_=q,015001450154015401570040016701570162015401440041,,*,=*|=*_,split+local$";
map{~$_&1&&{$,<<=1,[EMAIL PROTECTED]||3])=>~}}0..s~.~~g-1;*_=*#,
goto=>print+eval
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]