in reply to List Comparison
What sort of efficiency are you looking for? Time? Space? Coding?
Your code will make repeated scans of @a, being O(n**2), but it takes up almost no extra space.
Something like
trades space for time, making a single pass over @a and @b, at the expense of making a hash with the elements of @a as keys. If @a is really big, the memory footprint could become an issue.my %a = map { ($_, 1) } @a; @c = grep $a{$_}, @b;
Update: I see that you found stuff in CPAN while I was writing this; I was going to hit CPAN and post an update, but...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: List Comparison
by ketema (Scribe) on Sep 09, 2004 at 16:06 UTC |