in reply to Sorting and ranging problems...
my @list; my ($first, $last) = (undef, undef); NUM: foreach my $num (@read) { unless (defined $first) { $first = $last = $num; next NUM; } if ($num > ($last + 1)) { push @list, ($last > $first ? "$first-$last" : $first); $first = $last = $num; next NUM; } $last = $num; } push @list, ($last > $first ? "$first-$last" : $first) if defined $first;
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Sorting and ranging problems...
by Anonymous Monk on Sep 27, 2001 at 08:49 UTC |