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


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.