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"; } } }

In reply to remove element from 2D array after comparing it with other 2D array by Newbie95

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.