aging acolyte has asked for the wisdom of the Perl Monks concerning the following question:
In my journey to enlightenment I am looking for efficiency.
My problem is I have two arrays and I want to compare them and list those elements that are common to both and those that are unique.
e.g.
Now I am sure that this is a common problem and I know that a set of nested for loops would work - comparing each element in turn. But there must be a better way. Is it time for my understanding of map to grow beyond the "little black book" description?my @one = [1,2,3,4]; my @two = [2,4,6,8]; sub cf{...} common = [2,4]; unique_one = [1,3]; unique_two = [6,8];
Thanks
A.A.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Efficient Comparison of Array elements
by davorg (Chancellor) on Jan 08, 2003 at 15:54 UTC | |
by aging acolyte (Pilgrim) on Jan 08, 2003 at 16:29 UTC | |
|
Re: Efficient Comparison of Array elements
by LTjake (Prior) on Jan 08, 2003 at 16:10 UTC | |
|
Don't re-invent the wheel.
by dragonchild (Archbishop) on Jan 08, 2003 at 18:02 UTC | |
|
Re: Efficient Comparison of Array elements
by rir (Vicar) on Jan 08, 2003 at 16:36 UTC | |
|
Re: Efficient Comparison of Array elements
by jdporter (Paladin) on Jan 08, 2003 at 16:22 UTC | |
|
Re: Efficient Comparison of Array elements
by runrig (Abbot) on Jan 08, 2003 at 18:46 UTC |