Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

arrays on the fly??? is it possible

Status
Not open for further replies.

jamsman

Technical User
Jul 22, 2005
38
DE
i need to create a number of arrays on the fly, i dont know how many as the results come back form a database

any ideas

anymore information required please ask :)

thanks
 
Consider using two-dimensional arrays (arrays of arrays). With those, you can create as many arrays as you like and store them in the same data structure. Type `perldoc perllol' on the command line for a tutorial.
 
To follow up Ishnid's suggestions, if you create an array and you wish it to contain arrays of returned data and you don't know how many, all you need to do is loop collecting data from the db with something that returns an array reference like "fetchrow_arrayref" and push that returned value onto your array.
Code:
my $ref;
while($ref = $sth->fetchrow_arrayref()) {
  push @array, $ref;
}
# Here your main array contains all your rows of data each as an array

Does that help?


Trojan.
 
thats great i think i have enough to go on now

cheers
 
You might also like to use a module called Data::Dumper so that you can examine the data whilst you are developing the code (or you could always use "perl -d" and display your data structure with the "x" command!).


Trojan.
 
i have used the Data::Dumper alot really helpfull i find :) thanks for the advise
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top