Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

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

In addition to the comment made by the other monks, I'd like to describe a basic locigical flaw with this code. By using foreach my $row_ref (@$dataOut->fetchrow_array) you are actually iterating over columns, not rows. Changing this to use fetchrow_arrayref only changes it to be a foreach over a list with only one value (doesn't make any sense to do that). What you really meant to use there was fetchall_arrayref. This will return an array of arrays with all the data retrieved by your SQL query.

Update: After reading arturo's response, I'd like to add the following: using while(my @row = $dbh->fetchrow_array) is more memory efficient than using foreach my $row_ref ($dbh->fetchall_arrayref) but fetchall_arrayref may be faster (I'm not sure, it would depend on which DBD module was being used, you'd have to benchmark it). To speak to arturo's recomendation of using fetchrow_hash, it does make the code more maintainable, but less memory efficient, so it really depends on which is more important to you. You can achive the same effect as using fetchrow_hash using fetchall_arrayref by passing an empty hash ref in as an argument to the method.
HTH, Cheers


A truely compassionate attitude towards other does not change, even if they behave negatively or hurt you

—His Holiness, The Dalai Lama


In reply to Re: accessing data in DBI object by JediWizard
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 drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 22:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found