in reply to Quicker Array Searching

Without looking too deeply at the specifics, if you're constructing an array of items already seen, and checing the next item against every item in the array to make sure you haven't already seen it, there is definately another way to do it. You might consider using a hash instead.

my @things = qw/homer bart marge maggie lisa kramer jerry george elaine marge lisa/; my %seen; foreach my $thing ( @things ) { next if exists $seen{$thing}; $seen{$thing}++; # Do your stuff here. }

The above snippet keeps track of whether or not something's been seen already, and if it has, it skips to the next thing. If it hasn't seen it before, it makes a note of that thing, and then lets you do whatever processing you want.

The hash lookup is much faster than grep on an array.


Dave


"If I had my life to live over again, I'd be a plumber." -- Albert Einstein