I need to compare each element in one 2D array (array1_split_2D) with all of the element in another 2D array (array2_split_2D). But the problem here is the size for the array is different. So i want to use splice to delete the first element inside the array2_split_2D so that it will keep on comparing with the element in array1_split_2D. I put inside while loop so that if the (size of column for array1_split_2D != size of column of array2_split_2D), it will keep on looping and splice the element. But my code here delete all the array inside array2_split_2D while looping so it will be infinite looping in the while loop.
@array1 = ( 'ux_prim_clk', 'ux_side_clk', 'ux_xtal_frm_refclk'); @array2 = ( 'ccu_ux_xtal_frm_refclk_ack', 'ibbs_ux_prim_clkack', 'sbr_ux_side_clkack'); foreach(@array1){ @array1_split_2D = map {[split /_/,$_]} @array1; } foreach(@array2){ @array2_split_2D = map{[split /_/,$_]} @array2; } $match = 0; $highest_match_rate = 0; $array1_row_size = @array1_split_2D; $array2_row_size = @array2_split_2D; for ($i=0; $i<$array1_row_size; $i++) { print "\ninside first for loop\n"; $array1_column_size = @{$array1_split_2D[$i]}; #print "\nfirst column size = $array1_column_size\n"; #print "first: $first_line[$i][0]\nsecond: $second_line[$i_sec][$j +]"; for ($i_sec=0; $i_sec<$array2_row_size; $i_sec++) { $array2_column_size = @{$array2_split_2D[$i_sec]}; while ($array1_column_size != $array2_column_size){ print "\ninside while loop\n"; print "\ncolumn size array1: $array1_column_size\n"; print "column size array2: $array2_column_size\n"; for ($j=0; $j<$array1_column_size; $j++){ print "first[$i][$j]: $array1_split_2D[$i][$j] second[ +$i_sec][$j]: $array2_split_2D[ if ($array1_split_2D[$i][$j] eq $array2_split_2D[$i_se +c][$j]){ $match = $match + 1; print "$match\n"; } } $remove_first_column = splice @{$array2_split_2D[$i_sec]}, + 0, 1; print "remove = $removed\n"; } } }
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |