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 )
foreach $line ( @data )
This of course will make changes into the 'if' clause, but you have some existing problems in there already.
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".if ( @line[0] ...
Again, assuming it isn't a typo, you want to say
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 likeif ( $line[0]...
or ( and this is my preferred form )if ( $$line[0]...
Of course, you will need to substitute this change through the entire line, ie,if ( $line->[0] == $tree ... )
s/\@line/$line->/g;
Finally, the last assignment probably needs to look like
This will stash the current array reference into the right location for later use.$mdarray[$tree][$stem][$height] = $line;
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 :)
In reply to Re: Fail to see referencing problem to arrays (in an array of arrays)
by mikfire
in thread Fail to see referencing problem to arrays (in an array of arrays)
by Elias
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |