I am trying to compare all the array values (complete array) with a hash's value(which is array) and if the match founds,then push the key of hash to new array. The below code compare if the hash value is not array but how can I compare if its array?
%hash=(
storeA=>['milk','eggs'],
storeB=>['milk','fruits','eggs','vegetables'],
storeC=>['milk','fruits','eggs'],
);
@array = (
'fruits',
'milk',
'eggs'
);
Code to compare
use strict;
use warnings;
use Data::Dumper;
foreach my $thing (@array) {
foreach ((my $key, my $value) = each %hash) {
if ($value eq $thing) {
push @new_array, $key;
}
}
}
print Dumper(\@new_array);
Expected Output
@new_array = (
storeB,
storeC
);