in reply to Sorting and ranging problems...

Interesting homework problem. However, I'm in a generous mood. Next time, actually think before you post.
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
    what do you mean 'homework problem'? i need this for a message board program...a unique one in the aspect that it keeps track of which user has viewed which post, and doesnt display the ones they've read...(it stores read posts in a cookie)