i have two array of hashes: AH1 and AH2.
$AH1 = [
{
'id' => 123,
'name' => abc
},
{
'id' => 456,
'name' => def
},
{
'id' => 789,
'name' => ghi
},
{
'id' => 101112,
'name' => jkl
},
{
'id' => 1389,
'name' => mno
}
];
$AH2 = [
{
'id' => 123,
'name' => abc
},
{
'id' => 1389,
'name' => mno
},
{
'id' => 779,
'name' => ghi
}
];
how can i print hashes of AH1 that are in AH2 using Perl exists Function? or without having to iterate in the array.
existslocates by index, which are 0,1,2, and not 123,1389,779.existscan’t help.Furthermore, you must iterate over both array (one way or another) unless you switch one of the arrays to a hash.
In fact, switching is the easiest way to solve this.
It’s also quite efficient: You iterate over each array only once.