In Chapter 4, Section 4.8 (Computing Union, Intersection, or Difference of Unique Lists), the Perl Cookbook provides this technique for getting the intersection of two lists of integers:
@a = (1, 3, 5, 6, 7, 8);
@b = (2, 3, 5, 7, 9);
...
foreach $e (@a, @b) {
$union{$e}++ && $isect{$e}++
}
@union = keys %union;
@isect = keys %isect;
I want this to be done (case-insensitively) for two lists of strings. Any efficient method, please?
Array::Utils is what you’re looking for.
This produces the expected output of
Edit: I didn’t notice that you wanted this done case-insensitively. In that case, you can replace
@awithmap{lc}@a(and likewise with@b).