|
|
| more useful options | |
| PerlMonks |
Compare Lists (Non Unique Intersection)by rsiedl (Friar) |
| on Jul 28, 2006 at 01:37 UTC ( [id://564279]=perlquestion: print w/replies, xml ) | Need Help?? |
This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.rsiedl has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks, I'm trying to compare two arrays and find their "intersection". List::Compare has so far proved very useful, however I now need a non-unique intersection. Example code: This returns:
----------------------
Contents of Temp Array
test
test1
test
test2
test2
test
----------------------
Contents of Temp2 Array
test1
test2
test2
----------------------
The (Unique) Intersection of Temp and Temp2 Arrays
test1
test2
However I need the Intersection to look like:
The Intersection of Temp and Temp2 Arrays
test1
test2
test2
as test2 appeared twice in both lists.I cant find a way to do this with List::Compare, so can anyone suggest anything? Cheers, Reagen Update: but would still be interested in how you would go about it... For bonus points can anyone suggest a way to get the following: - The non-unique leftover from @temp; and, - The non-unique leftover from @temp2. I tried the following which doesnt work... Update 2: This works but seems long winded...
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||||||||||||