http://qs1969.pair.com?node_id=613645


in reply to Re^2: Populating an array from a mysql select
in thread Populating an array from a mysql select

Allow me to explain.

fetchall_arrayref returns an array ref, i.e. a scalar value which is a reference to an array (which will stringify as something like ARRAY(0x81503e8) if you try and print it out). You want to dereference this, and gain access to the array, hence the @{...}. This array has one element per row.

Unfortunately, this is not quite exactly what you want, as it's an array of arrayrefs. Each of the referenced arrays only has one element, as your SQL is only returning one column, but would contain more than one value if your query was returning more columns (note: there is no such method as fetchcol_arrayref).

The trick I have done is to fish out the element of each array, as the action for the map function. I could have written this as a for loop, but this kind of inline transformation lends itself to the builtins map and grep.

For further reading, see perlreftut.

--
wetware hacker
(Qualified NLP Practitioner and Hypnotherapist)