in reply to Comparing Two arrays
This is a faq, but here goes:
exists is used to prevent autovivication of new keys from @array1 in %hash.my @array1 = ("q", "w", "e", "r", "t", "z"); my @array2 = ("q", "w", "e", "r", "t", "y"); my %hash; @hash{@array2} = () x @array2; my @not_there = grep { ! exists $hash($_} } @array1;
Update: This method's run time is O(NlogN) or therabouts, while your attempt is O(N**2). ++fruiture for spotting a thinko, corrected.
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Comparing Two arrays
by sauoq (Abbot) on Sep 19, 2002 at 18:49 UTC |