> -----Original Message----- > From: Haitham N Traboulsi [mailto:[EMAIL PROTECTED]] > Sent: Friday, May 17, 2002 10:09 PM > To: [EMAIL PROTECTED] > Subject: help! > > > Hi, > I am working on a chunk of PERL software that can find out > the groups of consecutive numbers located within a list. For > instance imagine that the list contains 1, 2, 3, 4, 10, 14, > 15, 16, 20, 34, 35, 36,....................... > the program has to locate 1, 2, 3, 4 14, 15, 16 34, > 35, 36 as groups. I would appreciate any help with this > problem. thanks a lot.
Seriously homeworky, but something like this should work... use strict; my @list = (1, 2, 3, 4, 10, 14, 15, 16, 20, 34, 35, 36); my ($start, $end); while (@list) { $start = $end = shift @list; $end++, shift @list while $list[0] == $end + 1; print "Range from $start to $end\n" if $end > $start; } Destructive of the list, which must be sorted. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]