Link to home
Start Free TrialLog in
Avatar of KGNickl
KGNicklFlag for United States of America

asked on

Need Perl 2d Array help?

Need to create a 2d array in perl and I'm having one of those days where nothing I find online is making any sense to me. I wrote some fake code below to give you the flow and what i'm wanting to do. Any idea how to actually do this? Just need an example of a 2d array that consist of 3 columns (each an array). The array will get filled with a push in the loop that goes through each of the database row results.

Thanks! Let me know if there is any extra information I can use? Or if there is a better way to do this? For the DB query I'm using the DB Oracle something module.
my @array = (@columns1, @columns2, @columns3)
my @columns1;
my @columns2;
my @columns3;
#In the real code a query is run here and returns results w/ 3 columns and so many rows.

while( $query_results->fetch() ){
#Need to load up the multidimensial array here w/ the query results for each of the columns.

}  

#Then print here. But really I will be looping through the array and doing all kinds of stuff. But a loop example w/ printing the 2d array will give me enough info to get going.

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Carl Bohman
Carl Bohman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
One thing to keep in mind (and the reason why I didn't specifically loop to 3 for $col), in Perl, there's no constraint that says that each array will be the same length when you have a multi-dimensional array.  Perl lets each be completely independent.  You can make your code ensure a specific length if you want to.  Database query code should have a reliable length as long as the query is structured correctly and valid results are being returned.
SOLUTION
Avatar of wilcoxon
wilcoxon
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial