@myarray=();

You should probably use my @myarray; instead.

$currVar=\$myarray;

$myarray has nothing to do with @myarray.

$currVar=\$currVar[TableDepth1name];

You're taking a reference to the value stored in the array at that position. Because you're trying to build an array of arrays, the value stored in the array at that position is itself an array reference.

$currVar=\$currVar[TableDepth2name];

... and this is where things go really weird, because you're trying to treat a reference to an array reference as an array, and then take a reference to whatever Perl happens to autovivify at that position.

If you want the value in $myarray[TableDepth1name][TableDepth2name], write:

my $value = $myarray[TableDepth1name][TableDepth2name];

It's that easy if TableDepth1name and TableDepth2name are constants or functions which return valid indexes for the array of arrays reachable through $myarray. My guess is that they're not, and that you're not using strict and warnings, and Perl's doing its best to try to guess what you mean.

As I've mentioned before, you really need to get the hang of nested data structures before you go any further, because this is not the sort of thing that anyone can just throw together random syntactic elements and get the right results. It's one of the weirdest corners of Perl 5 and it takes some practice, but it has a logic and a consistency despite its quirks.

Improve your skills with Modern Perl: the free book.


In reply to Re^5: Working through it... by chromatic
in thread Working through it... by Inexistence

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.