"John W. Krahn" wrote: > > GöTz Verdieck wrote: > > > > 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 > > > > Any hint or code will help. > > Perhaps this will help: > > $ perl -le' > use Set::IntSpan; > my $kommalist = "20,21,22,23,24,25,27,28,31,32,33"; > my $set = new Set::IntSpan $kommalist; > my $newlist = Set::IntSpan::run_list $set; > print $newlist; > ' > 20-25,27-28,31-33
Or perhaps this: $ perl -le' $kommalist = "20,21,22,23,24,25,27,28,31,32,33"; ( $newlist = $kommalist ) =~ s/(\d+),(?=(\d+))/$1 + 1 == $2 ? "$1.." : "$1,"/eg; $newlist =~ s/\.\.\d+(?=\.\.)//g; print $newlist; ' 20..25,27..28,31..33 John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]