in reply to Searching first array in second array.
If it's ok an element from array1 may occur more than once in array2, I'd write:my @array1 = ...; my @array2 = ...; my %hash = map {$_ => 1} @array1; foreach my $e (@array2) { next unless exists $hash{$e}; die "Failure" if --$hash{$e} < 0; } die "Failure" if grep $_, values %hash; print "Success";
my @array1 = ...; my @array2 = ...; my %hash; @hash{@array1} = (); delete @hash{@array2}; die "Failure" if %hash; print "Success";
|
|---|