How can I get column names and row data in order with DBI in Perl?

前端 未结 5 1005
天涯浪人
天涯浪人 2021-02-19 22:42

I\'m using DBI to query a SQLite3 database. What I have works, but it doesn\'t return the columns in order. Example:

Query:  select col1, col2, col3, col4 from         


        
5条回答
  •  故里飘歌
    2021-02-19 23:25

    You're asking for the result as a hash. A hash is inherently unordered. Perhaps you want fetchrow_arrayref instead.

    In fact, if you had looked at keys %$row, you would have seen the corresponding keys being out of order as well. That's the nature of a hash... each key is paired with its value, but the overall ordering of keys or values is optimized for access, not external ordering.

提交回复
热议问题