in reply to Array Comparison
That nested loop is the killer. How about a hash? The following code is untested and unoptimized but performs better algorithmically:
my %exclude; @exclude{ @exclude } = (); my @cleaned = grep { exists $exclude{ $_ } ? () : $_ } @words;
Update: Yep, I confused grep with map in my pre-breakfast haste. That should rather be:
my @cleaned = grep { ! exists $exclude{ $_ } } @words;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Array Comparison
by Roy Johnson (Monsignor) on Dec 22, 2003 at 18:37 UTC | |
by mcogan1966 (Monk) on Dec 22, 2003 at 18:54 UTC | |
by Roger (Parson) on Dec 22, 2003 at 23:12 UTC |