#!/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 #1: $key\n" unless $hash{$key}--; } for my $key (keys %hash) { print "Fail #2: $key\n" if $hash{$key} > 0; }
For other related solutions, check out How do I compute the difference of two arrays? How do I compute the intersection of two arrays? in perlfaq4
In reply to Re^3: Compare arrays
by kennethk
in thread Compare arrays
by japhmi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |