in reply to Compare arrays
This is closely related to some FAQs: How can I tell whether a certain element is contained in a list or array? and How do I compute the difference of two arrays? How do I compute the intersection of two arrays?. The short answer is use a hash:
#!/usr/bin/perl use strict; use warnings; my @array1 = qw(a b c e); my @array2 = qw(a b c d); my %hash; for my $key (@array2) { $hash{$key}++; } for my $key (@array1) { print "Fail: $key\n" unless $hash{$key}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Compare arrays
by Anonymous Monk on Nov 01, 2010 at 18:11 UTC | |
by kennethk (Abbot) on Nov 02, 2010 at 14:21 UTC |