I want to make a loop where I go through all the elements in one array (@array1), and if the same element is found in another array (@array2), I want the value from a third array (@array3) with the same index to be added to the first array and deleted from the third array. I tried it this way, however the line with the if-statement runs on unitialized values, and it loops forever.
foreach my $elem1 (@array1){
my $i = 0;
while ($i < scalar @array2){
if($array2[$i]==$elem1){
push (@array1, $array3[$i]);
delete $array2[$i];
}
else{
$i++;
}
}
}