"Without using references"? By using two-dimensional arrays, you are already using references; two-dimensional arrays are actually arrays of arrays. See perlref, perldsc, perllol.
What you are looking for, I think, is the anonymous arrayref generator, which is a set of square brackets with a list inside, evaluating to a reference to a new anonymous array, contents being that list. Then you assign the reference to one of the elements of the "topmost" array. So, for example:
$two[4] = [ @one ];
will cause element 4 of @two (the two-dimensional array) to contain a reference to an anonymous array initialized from @one (a one-dimensional array), thus assigning @one to row 4 (counting from 0, assuming the indexing goes row, column). Again, see perlref, perldsc, perllol. | [reply] [Watch: Dir/Any] [d/l] |
Take a look at perldoc perldsc What you need can be done in the following way:
while (my @kp_src_t_row = $sth->fetchrow_array())
{
$currentarray[$kp_num]= [ @kp_src_t_row ];
$kp_num++;
}
--perlplexer | [reply] [Watch: Dir/Any] [d/l] |
Greetings keithbas,
Why exactly do you not want to use references? References are your friend. If I understand complex data structures (which maybe I don't), I'd think that any array of an array is built only by references.
Alternatively, you could push all the array data into a single, flat array. Assuming that the number of columns will never change, you could then just loop through the array...
push @currentarray, @new_data while (my @new_data = $sth->fetchrow_array);
This is really icky, IMHO, but you'd have your data in an array with no references...
-gryphon
code('Perl') || die;
| [reply] [Watch: Dir/Any] [d/l] |
What about:
my $currentarray = $sth->fetchall_arrayref;
I don't think @currentarray is the greatest of variables names...
gav^ | [reply] [Watch: Dir/Any] [d/l] |
Is it possible to assign an entire 1-D array to a row in a 2-D array without looping and without using references?
If you're new to references, and that is why you are wanting to not use them, I strongly suggest you sit down and get your head wrapped around them. You will not be able to implement complex data structures without them. And life will be much easier with them anyway.
If you don't understand references, I hope you don't feel dumb. Because it took me a long time for the concepts to settle in my brain. But one day I was talking with someone about it and it just clicked. From then on, it's been smooth sailing. Whatever time it takes you to understand references will be time well spent. In the long run you will benefit immensely.
And to answer your question, in many instances, you can't achieve what you're wanting anyway (the multi-dimentional part) without using references. To assign an array as an array element requires references - there is no other way.
Good luck & don't give up. | [reply] [Watch: Dir/Any] |