deleting elements in array in a loop Perl -


i want make loop go through elements in 1 array (@array1), , if same element found in array (@array2), want value third array (@array3) same index added first array , deleted third array. tried way, line if-statement runs on unitialized values, , loops forever.

    foreach $elem1 (@array1){         $i = 0;         while ($i < scalar @array2){             if($array2[$i]==$elem1){                 push (@array1, $array3[$i]);                 delete $array2[$i];             }             else{                 $i++;             }         }     } 

the problem not increment $i if element matches. delete else.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -