in reply to Question about fetchall_arrayref
(1) If you need to know the number of rows that meet the criteria for a query, ask the SQL servers to execute SELECT COUNT(*) AS numrows FROM ... to get a one-row result containing the count.
(2) Generally I think it is a much-preferred idea to retrieve rows one at a time, not to retrieve all rows. Also, to retrieve it as a hashref and to access the columns by their name. Your program should not care how many (millions of?) rows there might be, and it certainly should be written in the most descriptive, easy-to-understand and easy-to-maintain way possible.
Since this isn’t a code-writing service, I am not going to delve into the whys or the wherefores of your particular program.