I'm using CGI.pm, v 2.80 to create popup_menus from DBI queries. For some reason, the "-labels=>" option in popup_menu isn't working- I'm not getting the IDs as the values.

sub create_cat_list{ my ($type,$dbh)=@_; my $cat=$dbh->prepare("select ${type}_cat,${type}_id from ${type}_cat + order by ${type}_cat"); $cat->execute(); my @list; my %hash; while(my ($catval,$id)=$cat->fetchrow_array()){ push @list, $catval; $hash{$id} = $catval; } $cat->finish(); return [ \%hash,\@list ]; } ## SNIP my $l1=create_cat_list('l1',$dbh); $output.=$q->popup_menu(-name=>'l1_cat',-values=>$l1->[1],-labels= +>$l1->[0]);

The popup_menu doesn't end up with the -labels being applied to it. Using Data::Dumper, the hash ref comes through from create_cat_list() fine. Is this a bug in CGI 2.8.0? I completely don't understand what's going on. Data::Dumper output of create_cat_list() is below.

$VAR1 = [ { '1' => 'Canadian Paper Money', '2' => 'US Coins', '3' => 'US Paper Money', '4' => 'Supplies', '5' => 'Canadian Coins' }, [ 'Canadian Coins', 'Canadian Paper Money', 'Supplies', 'US Coins', 'US Paper Money' ] ];
and here's the HTML being output.
<select name="l1_cat"> <option value="Canadian Coins">Canadian Coins</option> <option value="Canadian Paper Money">Canadian Paper Money</option> <option value="Supplies">Supplies</option> <option value="US Coins">US Coins</option> <option value="US Paper Money">US Paper Money</option> </select>

Maybe I'm missing the obvious, but what the heck is going on here?

-Any sufficiently advanced technology is
indistinguishable from doubletalk.


In reply to Strange CGI.pm -labels= behaviour by Hero Zzyzzx

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.