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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.