Toppo has asked for the wisdom of the Perl Monks concerning the following question:
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?
Jon
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: An Array Without and Index
by Marshall (Canon) on Aug 13, 2012 at 08:58 UTC | |
|
Re: An Array Without and Index
by Anonymous Monk on Aug 13, 2012 at 08:46 UTC | |
|
Re: An Array without an Index
by Athanasius (Archbishop) on Aug 13, 2012 at 09:01 UTC | |
by Anonymous Monk on Aug 13, 2012 at 09:10 UTC | |
by CountZero (Bishop) on Aug 13, 2012 at 13:54 UTC | |
by Anonymous Monk on Aug 13, 2012 at 14:10 UTC | |
|
Re: An Array Without and Index
by Neighbour (Friar) on Aug 13, 2012 at 09:08 UTC | |
|
Re: An Array Without and Index
by CountZero (Bishop) on Aug 13, 2012 at 13:50 UTC | |
|
Re: An Array Without and Index
by aaron_baugher (Curate) on Aug 13, 2012 at 12:32 UTC | |
by Anonymous Monk on Aug 13, 2012 at 12:51 UTC | |
by aaron_baugher (Curate) on Aug 13, 2012 at 13:21 UTC |