in reply to
Perl - DBI - How to process array rather than single value?
Three short answers:
- If you need the results of an SQL query to appear in a particular sequence, let the SQL engine do it via ORDER BY.
- If you do get an arrayref as the result, use foreach to iterate through it.
- However, the arrayref approach would be problematic for a large number of records since all of them would be stored in your program’s memory first. You can avoid this issue by retrieving the rows one row at a time, say into a hashref where the hash-keys are the column names, using an ordinary while loop.
There are, of course, copious examples of this on the Internet, both here and elsewhere and to a certain extent within the documentation and manuals for DBI. (Click on the product-name at the top of that page, right next to the package-author’s name, to see the full list of help-topics associated with the package. Do a search on the package-name to find even more goodies.) Usually, you can quickly solve questions like these by surfing for an existing code-example ... a very powerful strategy otherwise not-so diplomatically known as: “RTFM.” ;-)