http://qs321.pair.com?node_id=1040243


in reply to How does DBI return an arrayref with key/value pairs?

As BillKSmith pointed out:

 { Slice => {} }

is your answer. The Slice tells DBI what format you want the selected records to be returned as. You've asked for them to be returned as hash references {} so that's what you get.

You could have also used:

 { Slice => [] }

in which case, each selected row would be returned as an array reference. You wouldn't get the table column names (hash keys), instead you would just get an array of the row values and it would be up to you to remember the order of the columns selected.

Returning the records as hash references is slower than returning the records as array references. But returning records as array references can make the code harder to read (and harder to find bugs). Especially if you select all columns generically using queries like "Select * From". Returning the records as array references could blow up on you horribly in this situation if the database table layout changes in the future. I avoid using "Slice => []" unless the number of columns selected is small or I'm expecting huge numbers of returned records and performance is critical.