Given two arrays (with duplicates), one a proper subset of the other, produce a third array containing those in the first not in the second. Eg.
my @a = (43,43,44);
my @b = (43,43);
## Required result
my @c = (44);
my @p = ( 1,1,1,1,1,2,2,2,3,3,4,5,6);
my @q = ( 1,2,3,4,5,6 );
## Required result
my @r = ( 1,1,1,1,2,2,3 );
The FAQ solution produces both intersection and difference, and more than doubles memory usage in the process.
List::Compare more than quadruples memory usage on it's way to calculating about fifty things I don't need as well as the one I do.
Most of the other CPAN and Categorised answer solutions don't handle duplicates, use large amounts of memory, or both.
Is there a simple variation on a using a hash and grep that works? Cos I'm not seeing it written anywhere and its eluding me.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.