in reply to How do I compare two arrays?
Another solution (that I didn't see mentioned there) is to transfer elements of one array into a hash, and use that.
Such a method uses more memory space but is faster (unless you use so much memory you start swapping :-)
The code would look somewhat like this:
map($a1{$_}=1,@a1); # create %a with elements from @a1 @a2=grep(!defined($a1{$_}),@a2); # returns those elements of @a2 that +don't # have a hash element in %a1 therefore they # do not exist in @a1.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How do I compare two arrays?
by Corion (Patriarch) on Mar 09, 2004 at 08:07 UTC |