Hi all,
I'm using CGI/DBI to access an Oracle DB, which is something I've done in the past. Many query forms will use popup_menu's to help out the users. My question is about how to populate those boxes efficiently. For boxes that do not have separate labels and values I can always use:
$cgi->popup_menu( -name => 'unigene_build', -values => [@{$dbh->selectcol_arrayref($sql)}], )
Which looks reasonably clear and efficient to my eyes. I'd be very happy to see better ways of doing that, but more troublingly is the idiom I've been using for popup's that need separate labels and values, which is:
$sth_menu->execute(); while (my $ref = $sth_menu->fetchrow_arrayref()) { $menu{$$ref[0]} = $$ref[1]; } $cgi->popup_menu( -name => 'external_database_id', -values => [keys(%menu)], -labels => \%menu );
Incidentally I knowingly left out some stuff here (like the prints and variable declarations and so forth. I hope the idioms I'm using are clear.
The problem I have with the latter code fragment is that I have to create a hash and populate it, after which CGI goes ahead and loop through the hash *twice* -- once to get the values (via keys()) and once to associate each value with the appropriate label. Seems wasteful to me (although this couldn't possibly be an issue given the lack of load on my DB). Is there a better way fellow monks?
In reply to Populating CGI popup_menu via DBI by Itatsumaki
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |