Q:

Looping through 2D array in Perl?

If I have a 2D array, how can it be possible to access an entire subarray inside of loop?  Right now I have
foreach my $row(@data){  
 foreach my $ind(@$row){  
  #perform operations on specific index  
 }  
}

but ideally I'm looking for something along the lines of 
foreach my $row(@data){  
  #read row data like $row[0], which if it has the data I'm looking for  
  #I can go ahead and access $row[3] while in the same row..
}  

I'm fairly new to Perl so might just not understand something yet, but I keep "Global symbol "@row" requires explicit package name" when trying to use it the way I want to.

A:

You're close. $row is an array reference and you access its elements with the deference operator ->[...]:
foreach my $row (@data) {
    if ($row->[0] == 42) { ... }

$row[0] refers to an element of the array variable @row, which is a completely different (and probably undefined -- thus the Global symbol ... error message) variable than $row.

A:

If $row in your code sample is supposed to be a sub-array, or an array reference, you will have to use the indirect notation to access its elements, like $row->[0], $row->[1], etc.
The reason for your error is because $row[0] actually implies the existence of an array @row, which is probably not present in your script.

