in reply to Fail to see referencing problem to arrays (in an array of arrays)

Assuming it is not a typo, you have several problems in this loop. I will start at the top and move down.
foreach @line ( @data )
I am not sure if this is a typo. What we refer to as "an array of arrays" is really an array of references. In this case, I think you meant:
foreach $line ( @data )

This of course will make changes into the 'if' clause, but you have some existing problems in there already.

if ( @line[0] ...
does not do what you think. You are referencing an array slice consisting solely of the first element in @line. Perl will DWYM and give you the referenced element of the array. Using -w would have caught this "mistake".

Again, assuming it isn't a typo, you want to say

if ( $line[0]...
in the generic case. In this case, though, since we have changed @line to $line ( ie, from an array to an array ref ), it really should look like
if ( $$line[0]...
or ( and this is my preferred form )
if ( $line->[0] == $tree ... )
Of course, you will need to substitute this change through the entire line, ie,
s/\@line/$line->/g;

Finally, the last assignment probably needs to look like

$mdarray[$tree][$stem][$height] = $line;
This will stash the current array reference into the right location for later use.

All in all, I would highly recommend reading through perldsc ( the perl data structures cookbook ). I found it very useful when I was first learning how to handle perl's data structures. I would also recommend always developing with -w and use strict :)

mikfire

Replies are listed 'Best First'.
Re: Re: Fail to see referencing problem to arrays (in an array of arrays)
by Elias (Pilgrim) on Apr 25, 2001 at 14:56 UTC

    Thanks for the explanation and suggestions. As it turns out the root of my confusion lay in accessing the resulting array. Just for completeness sake: I needed to check the existence of a reference using defined before printing.

    for my $tree (0..17) { for my $stem(0..10) { for my $height (0..2) { my $line=$mdarray[$tree][$stem][$heigh +t]; if (defined @$line) {print "$tree,$ste +m,$height : @$line \n" } } } }