Hi Bob
In general a hash is the way to go:
my @list1 = qw ( Apple Orange Lemon Tangerine Grape );
my @list2 = qw( Apple Tangerine Grape Banana );
my %list1 = map {($_ => 1) } @list1;
my @list3 = grep {$list1{$_}} @list2;
print "@list3";
output:
Apple Tangerine Grape
H
C:\>perldoc -q intersection
Found in C:\Perl\lib\pod\perlfaq4.pod
How do I compute the difference of two arrays? How do I compute the
intersect
ion of two arrays?
Use a hash. Here's code to do both and more. It assumes that
each element is unique in a given array:
Bob Williams wrote:
I have two lists.
List 1 is the control list containing: Apple, Orange, Lemon, Tangerine, and Grape.
List 2 contains Apple, Tangerine, Grape, and Banana.
I need a script that compares the two lists and will eliminate banana from list 2 because banana is not in the control L