Tuesday, 1 October 2013

Looping through 2D array in Perl?

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.

No comments:

Post a Comment