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 |