In article <[EMAIL PROTECTED]> wrote "Ron Goral" <[EMAIL PROTECTED]>:
> Can someone please tell me why the following code only returns the last element in >the referenced > array? If I put the foreach routine inside the while loop, I get a printout of each >element in > both the $sqlRes reference and the $colNames reference. But, if I print outside the >while loop, I > only get the last reference put in the $sqlRes reference. Please help. > > # Reference to a set of references > my $sqlRes; > > # Fetch each row of data, put into an array ref and push into the main array ref. > while (my $colNames = $sth->fetchrow_arrayref) > { > push(@{$sqlRes},$colNames); $colNames is a refernence to an array. $sqlRes is a reference itselves. So $sqlRes has ca. that outlook $sqlRes = [ [@$colnames1], [@$colnames2], ...]; > } > > foreach my $arrayRef(@{$sqlRes}) > { > foreach my $refRef(@{$arrayRef}) > { > print $refRef; What you really neaded is print @$refRef; > print qq[<br>]; > } > } A shorter way is: push @{$sqlRes}, $_ while ($sth->fetchrow_arrayref); foreach (@{$sqlRes}) { print join("", map{"$_<br>"}) foreach (@$_); } Best Wishes, Andrea -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]