in reply to Re^4: Working through it...
in thread Working through it...
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Working through it...
by Inexistence (Acolyte) on Sep 12, 2011 at 05:23 UTC |