The standard way to get rid of duplicates is:
my %seen; my @filtered = grep !$seen{$_}++, @arr2;
The difference is that you only want to remove duplicates of elements present in @arr1. Let's adapt the above:
my %seen; my %in_arr1 = map { $_ => 1 } @arr1; my @filtered = grep !$in_arr1{$_} || !$seen{$_}++, @arr2;
In reply to Re: Comparing arrays in perl.
by ikegami
in thread Comparing arrays in perl.
by anand_perl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |