I'd be interested to know why you're pulling columns in the database out and using them as both keys and values in the hash. It doesn't seem to be the most efficient way to do things. What does your database table look like? I was going to suggest reading up on
DBI, specifically the statement handle method
fetchrow_hashref(). After I went back and actually read your code a little close, I realized this likely wouldn't help you. If you have a table of votes you might consider setting up the tables so its a
little eaiser to make data retrieval much easier.
Also note that the "SELECT * FROM" using
fetchrow_array and
fetchrow_arrayref are not very maintainable. For instance, if you were to change the order of fields while altering the table to add a new column, you would need to redo
every select statement and the stuff around it. If you want to grab
all the fields, consider using
fetchrow_hashref, which is slightly slower than
fetchrow_arrayref but it MUCH more maintainable. Personally, I'd recommend not pulling out more data than necessary, and explicity specifying the columns to pull out in the select statement. This allows you to control the order of the array. This would be useful to your code taking it from the above to:
...
my $SELECT = qq/select field1, value1 , field2, value2 from table/;
my $sth = $dbh->prepare($SELECT);
$sth->execute;
while( my $row = $sth->fetchrow_arrayref ) {
my %hash = @$row;
.....
}
The rest of that code, I can't make heads or tails of why you'd want to store things like that. I can provide more help if I knew what columns you were pulling out and why you're handling them the way you are.
-brad..