Your code should work as it is.
The advice I can give you is the same you may find at Before asking a database related question ..., where it is outlined how to test your SQL before resorting to the script.
Additionally, you may see some different ways of creating an array from a DBI call in DBI Recipes.
My favorite is :
my $arrayref = $dbh->selectcol_arrayref($query);
HTH
In reply to Re: creating an array from MySQL results
by rnahi
in thread creating an array from MySQL results
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |