Itatsumaki has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Populating CGI popup_menu via DBI
by jsegal (Friar) on May 29, 2003 at 22:06 UTC | |
by Itatsumaki (Friar) on May 30, 2003 at 14:10 UTC | |
by KPeter0314 (Deacon) on May 30, 2003 at 14:34 UTC |