Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: accessing data in DBI object

by arturo (Vicar)
on Apr 14, 2005 at 15:16 UTC ( #447834=note: print w/replies, xml ) Need Help??

in reply to accessing data in DBI object

It helps us help you if you can say what's not working, e.g. what error message is perl giving you when you try to execute the code. That said, there are a couple of things that jumped out at me:

  • foreach my $row_ref ... but inside the loop, you're referencing a thing you think is an array reference with the name row_ary; if you're using strict, this should be caught at compile time.
  • you're getting an error message that looks like Not an ARRAY reference at your foreach line, because @$object->method treats $object as an array reference

(Also, what you probably meant to write ( @{$DataOut->fetchrow_array} ) won't work either, because fetchrow_array returns the row's data as an array.

So the following loop rewrite should help you get over the two problems I've mentioned:

while ( my @row = $DataOut->fetchrow_array ) { my $fname = $row[0]; # ... }

An even better solution, IMO, would be to use fetchrow_hashref so the columns have readable names and you don't have to go back to the SQL to figure out which column maps onto which variable.


If not P, what? Q maybe?
"Sidney Morgenbesser"

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://447834]
marioroy running LWP::Simple on Cygwin in parallel completes in 1 second. Pre-loading essential modules is necessary only on MSWin32 Re: Crash with ForkManager on Windows.
marioroy LWP::Simple works best with Perl v5.26 on Windows. Any Perl version is fine on Cygwin and Unix.
[karlgoethebier]: Hi mario

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2017-09-23 15:49 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (272 votes). Check out past polls.