Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.

HTH

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


In reply to Re: accessing data in DBI object by arturo
in thread accessing data in DBI object by arcnon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-20 03:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found