in reply to Two dimensional array

@temp_array is two dimensional.
How do you construct your array?

If your array is an array of rows, each row containing two columns, it should be something like

@array = ( [ 1, 2 ], [ 3, 4 ], [ 2, 5 ], );

Now, if you want to find the row that contains the values 3, 4

$temp = 3; $temp_1 = 4; @matching_rows = grep { $_->[0] == $temp && $_->[1] == $temp_1 } @arra +y;

With the above @array the resulting array consists of one element, which is an anonymous array containing the values 3 and 4. See perlref and perlreftut for the [ ] constructor.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: Two dimensional array
by Anonymous Monk on Oct 03, 2007 at 20:46 UTC
    I have the 2D array built from two arrays containg strings:
    @temp_array = (\@arry1, \@arry2); my @exists = grep { $_->[0] eq $temp1 && $_->[1] eq $temp2} @temp_a +rray ;
      Well, that changes things. Sticking to the row/column view, you have arrays of columns. Are those column arrays equal in element number?
      my @exists = grep { $temp_array[$_]->[0] eq $temp1 && $temp_array[$_]->[1] eq $temp2 } 0..$#{$temp_array[0]};

      The resulting @exists will contain the indexes into the two anonymous arrays your @temp_array holds where the comparison values are at the same index.

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}