japhmi has asked for the wisdom of the Perl Monks concerning the following question:
I have 2 arrays, and I need to make sure all elements of array 1 are in array 2, but array 2 can have extra elements.
Examples:
OK:
@array1 = (a b c) @array2 = (a b c)
OK:
@array1 = (a b c) @array2 = (a b c d)
OK:
@array1 = (p d q) @array2 = (d p q)
NOT OK:
@array1 = (a b c e) @array2 = (a b c d)
The method that I've come up with so far is clunkey, with a copy of array2, and then 2 foreach loops, deleteing items from my copy - it's a mess and seems to like messing up. I'm looking for something more elegant.
Thank you monks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Compare arrays
by dorko (Prior) on May 28, 2010 at 18:48 UTC | |
|
Re: Compare arrays
by kennethk (Abbot) on May 28, 2010 at 17:25 UTC | |
by Anonymous Monk on Nov 01, 2010 at 18:11 UTC | |
by kennethk (Abbot) on Nov 02, 2010 at 14:21 UTC | |
|
Re: Compare arrays
by Argel (Prior) on May 28, 2010 at 21:29 UTC | |
|
Re: Compare arrays
by Khen1950fx (Canon) on May 29, 2010 at 00:58 UTC | |
|
Re: Compare arrays
by kalyanrajsista (Scribe) on May 29, 2010 at 15:32 UTC | |
|
Re: Compare arrays
by baxy77bax (Deacon) on May 29, 2010 at 16:31 UTC |