Kurt wrote:
> 
> I'm working with a database interface (DBI) that returns information
> by returning a reference ($Z) to an array of arrays.
>
> ...
> 
> When I write $Z->[2][3] I get the expected  -81.3439.
> 
> Now the questions:
> 
> If I want to iterate over each of these elements, to print out a line
> at a time, how do I do it?
> 
> Of course, I could do something like this:
> 
> for (i=0;i<ARRAYSIZE;i++) {
>         for (j=0;j<SIZEOFINNERARRAY;j++) {
>                print "$Z[i][j],"  ";
>          }
>           print "\n";
>      }
> 
> But this isn't very "Perl-like" and  it leaves the question of how do
> I know the  ARRAYSIZE and SIZEOFINNERARRAY (which is known in this
> case, but as a general case, may not be known)?
> 
> I'd like to use something like a nested "foreach" loop... and the
> code should evaluate the size of each innermost array - so for
> example, if an inner array had size 4 instead of 7, it would be
> detected (so I don't iterate over non-existent values).
> 
foreach my $row (@$Z) {
    foreach my $col (@$row) {
         print $col,'  ';   # prints $Z->[i][j]
    }
    print "\n";
}

or quite some more perlish:
print join ("  ", @$_), "\n" foreach @$Z;


Best Wishes,
Andrea

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to