On 4/7/2004 5:50 PM, Randy W. Sims wrote:

On 4/7/2004 5:45 PM, Romain Groleau wrote:

Hi,

my sql query is select a,b ....

and the code to store the results in stach is :

my @stach;
while( my @ary=$sth->fetchrow_array()) {
push @stach, [EMAIL PROTECTED] ;
}

and this doesn't work if I look at @stach there are
only ARRAY(0x81cff60) in the two columns of @stach.


my @stach;
while(my @ary = $sth->fetchrow_array()) {
  push @stach, [EMAIL PROTECTED];
}

use Data::Dumper;
print Dumper([EMAIL PROTECTED]);

Oops, sent that too soon.


In perl, a multidimensional array is an array of arrays, i.e. one array holds an array in each slot.

Imagine an array with 3 slots. (where a slot is represented by [])

@a=
[]
[]
[]

Now imagine that each slot holds a reference to an array, so it looks like:

@a =
[] -> [][][]
[] -> [][][]
[] -> [][][]

To access an element, you have to access the row which returns a reference to the array of columns

$ra = $a[1]; # access row index 1 and store reference to array of columns

Then to get the item in a specific column, you dereference the array:

$ra->[1]; # dereference and access element 1

To do it all in one step:

$a[1]->[1];

or, just:

$a[1][1];

Regards,
Randy.





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to