Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: accessing data in DBI objectby JediWizard (Deacon) |
on Apr 14, 2005 at 15:16 UTC ( [id://447835]=note: 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. A truely compassionate attitude towards other does not change, even if they behave negatively or hurt you His Holiness, The Dalai Lama
In Section
Seekers of Perl Wisdom
|
|