in reply to number sequence
You want Set::IntSpan. The only way I know this is that newsrc files use that format, and that's what News::Newsrc uses. :)
Update: bobf notes that Set::IntSpan needs a run in increasing order, and that most solutions pretty much do the same thing that I've done below. However, I'm thinking about the next part of the problem, where some part of the program is going to ask if a value is in that list. Making the range is easy with simple Perl. Getting data out of it is a bit more complicated. :)
#!/usr/bin/perl use Set::IntSpan; while( <DATA> ) { chomp; my $set = Set::IntSpan->new( join ",", sort { $a <=> $b } split /,/, $_ ); print "$_ ---> @{ [ $set->elements] }\n"; } __END__ 80 17-199 18,512,21,78 18,5,1790,19-66,212,213
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: number sequence
by bobf (Monsignor) on Mar 24, 2007 at 03:57 UTC |