I'm trying to create a database .Each element in list contains details in the form of associative array and the last element of each of these associative array is a 2-d array,i need help initializing it ..
Asked
Active
Viewed 75 times
-5
-
3Perhaps you should provide some sample input. And some sample code. – TLP Nov 16 '12 at 19:43
-
2Have you read about auto-vivification? – Tim Nov 16 '12 at 19:46
1 Answers
1
You need to say much more about what it is you are trying to do, but this may help: it initialises a Perl data structure in the way you have described. Note that there can be no "last" element of a hash (a better name than "associative array") as hashes are unordered. I have used the customers
field of the data to hold the 2D array you talked about.
use strict;
use warnings;
my @list = (
{
id => 1,
name => 'cattle',
customers => [
[ 'World Bank', 'Space Marines', 'Undersea Exploration' ],
[ 1, 2, 3 ],
[ 0.0500, 0.6322, 0.9930 ],
],
},
{
id => 2,
name => 'arable',
customers => [
[ 'Jack Spratt', 'Molly Malone', 'The Whistler' ],
[ 4, 5, 6 ],
[ 0.0022, 0.1130, 0.6930 ],
],
},
{
id => 3,
name => 'seafood',
customers => [
[ 'Tai Chi School of Fishery', 'Latin Intermediary College', 'Ping Pong Gymnastics' ],
[ 7, 8, 9 ],
[ 0.0012, 0.8540, 0.9817 ],
],
},
);

Borodin
- 126,100
- 9
- 70
- 144
-
thank you for taking interest and sorry i forgot to mention that i'm trying to take the input from the user itself i'm having trouble understanding how append the grouped data with the list properly and perform delete or insertion operations on it.. – Sayan Paul Nov 16 '12 at 23:10