Raydot
asked on
Dereferencing a 2D array?!
Hello all,
I'm having a nasty time with the following code:
push @endArray, [$arrayToSort[$i][0], $arrayToSort[$i][1]];
I'm trying to push the contents of one 2D array into another, one item at a time. In the above example, I'm trying to do it by (making a fool of myself and) creating a mini-array to push onto @endArray.
The thing is, almost every flavor of what I've tried has given me the ADDRESS of the array item, and not the 2D value of the item itself. What am I doing wrong? Do I need to dereference this address? Is there another way to pass this info??
Thanks,
Raydot.
I'm having a nasty time with the following code:
push @endArray, [$arrayToSort[$i][0], $arrayToSort[$i][1]];
I'm trying to push the contents of one 2D array into another, one item at a time. In the above example, I'm trying to do it by (making a fool of myself and) creating a mini-array to push onto @endArray.
The thing is, almost every flavor of what I've tried has given me the ADDRESS of the array item, and not the 2D value of the item itself. What am I doing wrong? Do I need to dereference this address? Is there another way to pass this info??
Thanks,
Raydot.
ASKER
Ah...it's not the grabbing back that isn't working, it's the putting in. The push command itself is no good...
Or wait, no it isn't, I did try it and it worked. So you're saying the problem was not my push, but my pop?
Could you just break down for me what you're doing with:
@ArrToSort = @$Level1;
?
Thanks...
Or wait, no it isn't, I did try it and it worked. So you're saying the problem was not my push, but my pop?
Could you just break down for me what you're doing with:
@ArrToSort = @$Level1;
?
Thanks...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Just the answer I was looking for. If only all respondents were quite this diligent...
Thanks,
Raydot.
Thanks,
Raydot.
Here is a demo for you of how to grab your data back.
$arrayToSort[1][0] = "First Element";
$arrayToSort[1][1] = "Second Element";
push @endArray, [$arrayToSort[1][0],$array
foreach $Level1 (@endArray)
{
@ArrToSort = @$Level1;
foreach $Level2 (@ArrToSort)
{
print "$Level2\n";
};
};
Try it.