in reply to How to compare two arrays under certain conditions?
The code in perlfaq4 sadly assumes no duplicates. But nonetheless hashes are the solution:
foreach @b { $hb{$_}++ } foreach @a { $ha{$_}++ } foreach keys %hb { push @c,$_ if ( not exists $ha{$_} ); }
This code should be easier to grok than the dense code in the perlfaq. Because %hb is a hash, "keys %hb" is identical to @b without the duplicates. In the loop a value gets pushed into @c if it is not in %ha and so also not in @a.
You might be able now to create a second loop that finds "all the elements in @a are all belong to @b".
|
|---|