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..
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.