I'm still a newbie and am having problems with arrays created from output with DBI.
I've got a table with two columns; one is an address(VARCHAR), the other is an arbitrary id number (INT). An earlier query based on the same code successfully creates an array of addresses. The bit I'm having trouble with tries to create a corresponding array of id numbers for that address array.
My, very basic, code (using strict and warnings) looks like this:
foreach $addr (@addr){ $addr_lookup = "SELECT u2addr.id FROM u2addr WHERE u2addr.addr = \ +"$addr\";"; $stm = $dbh->prepare($addr_lookup); $stm->execute; @results=(); @row=(); while (my @row = $stm->fetchrow_array){ push (@results, @row); }#end of while $stm->finish; print $results[-1]; }
Now the problem is that the elements of the array @results don't appear to have an index, so the $results[-1] throws back all the content of @result.
I've tried reworking the code to use selectcol_arrayref, as per the DBI recipes, but no change.
To make matters more frustrating, if I pull the output of the fetchrow_array into a scaler al la:
the output is individual values followed by a comma, so the database output is as expected. However, if i try and push the scaler values into an array this array also has no index and an $results[-1] throws back all the content...while (my ($uid_value) = $stm->fetchrow_array){ print "$uid_value, "; }#End of While
I know the code I'm using is primitive but what am I missing here?
JonIn reply to An Array Without and Index by Toppo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |