Grr! Intersection & difference of arrays is something that ought to be in core.
Looked in List::MoreUtils to no avail.
I looked at cpan and downloaded Array::Utils but it can't handle duplicates.
Looked at List::Compare, but it comes complete with the kitchen sink & waste disposal (aliased as Belfast Sink & waste bin) and calculates 20 different things under the guise of "initalising".
Could you post an example of input array and expected outputs please.
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.
| [reply] |
Sure!!!
If @array = (40,17,40,30,40,25,40); is given
something like
@subarray1 = (40,40,30)
@subarray2 = (40,40,17,25)
should be returned.
I guess you already have your own sources, but for intersection of arrays I always use a function from PerlFAQ 4:
@union = @intersection = @difference = ();
%count = ();
foreach $element (@array1, @array2) { $count{$element}++ }
foreach $element (keys %count) {
push @union, $element;
push @{ $count{$element} > 1 ? \@intersection : \@difference }
+, $element;
}
Let me know if you need more examples, or what kind of them are you looking for
| [reply] [d/l] |
return \@best, [ grep{ !--$seen{ $_ } <= 0 } @$aRef ];
The trouble with the FAQ is it conflates two things.
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.
| [reply] [d/l] |