Hi -
Please try:
use strict;
my @list = (1, 2, 3, 4, 10, 14, 15, 16, 20, 34, 35, 36,);
my %conseq; # temp hash
$conseq{$_} = $_ for (@list);
for (keys %conseq) {delete $conseq{$_} unless $conseq{$_-1} or
$conseq{$_+1}}
my @conseq; # result (note: remember scalars, arrays, hashes
# have their own namespaces, so same "name" is ok)
push @conseq, $_ for (sort {$a <=> $b} keys %conseq);
print "$_\n" for (@conseq);
Maybe people will yell at me because it's such a kludge, but it works:
1) copy to hash with the key the same as value,
2) pass hash deleting keys that don't have +1 or -1 neighbors,
3) numerically sort hash and populate result array.
Oh, well...
Aloha - Beau.
-----Original Message-----
From: Haitham N Traboulsi [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 17, 2002 4: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.
Best wishes.
Haitham N Traboulsi
------------------------------------------
Department of Computing
University of Surrey
GU2 7XH
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]