P is for Practical | |
PerlMonks |
Re: DBI Fetchrow_hasref issueby jarich (Curate) |
on Feb 21, 2004 at 18:21 UTC ( [id://330839]=note: print w/replies, xml ) | Need Help?? |
It would make the code cleaner and easier (I thought) if I fetched a hash instead of an array (like usual). fetchrow_hashref is best when you're selecting a number of things out from the database and you don't want to have to care what order you're doing that in. For example: would give us a reference to a hash with the keys "name", "address", "phonehome", "phonework" and their values would be the values from the db. Note that this hash would only contain the values for ONE entry. The next time we called fetchrow_hashref we'd get the values for the next entry. And so on. Considering that you've said that you just want to dump all the values from the hash into an array I get the distinct impression that you're SQL is more like: If this is the case then your code isn't going to do what you want it to anyway. $info is going to be set to something like: and you're going to print out "name". Even if you try to capture all of the values from this hash you're only going to get "fred" this time through the loop and "julie" next time through the loop... You can achieve what you want with the following: However that's not really the best way to be doing this. I think what you're looking for is selectcol_arrayref. This selects all the (appropriate values) from a single column and returns an array ref to them. So this: gives you all the values in the "name" column of the database which matched your where clause. You can then use $names (or @case in this instance) to do whatever you need. I hope this helps jarich
In Section
Seekers of Perl Wisdom
|
|