I'm populating a HTML drop down menu using CGI's popup_menu method. The popup_menu method says you can generate the drop down menu with a Hash Reference. I believe I have a Hash Reference generated from a call to a DB but I'm getting "HASH(0xa278214)" instead of my desired output. I searched the Perl Monks archive and the net but couldn't figure it out.
What am I doing wrong with this code?#!/usr/bin/perl -wT
use DBI;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use Data::Dumper;
my $cgi = CGI->new(); # Create new CGI object.
my $database = "db";
my $db_server = "localhost";
my $user = "user";
my $password = "pass";
my $dbh = DBI->connect("DBI:mysql:$database;host=$db_server", $user,
$password) or die $DBI::errstr;
my $authorSQL = "SELECT idAuthor, Author FROM Author ORDER BY Author";
my $hash_ref = $dbh->selectall_hashref($authorSQL, "idAuthor");
print $cgi->header;
print $cgi->start_form;
print Dumper($hash_ref);
print $cgi->popup_menu(-name=>'menu_name',
-values=>[$hash_ref]);
print $cgi->end_form;
Here's my HTML output from the code above<form method="post" action="/cgi-bin/addlocation.pl" enctype="multipar
+t/form-data">
$VAR1 = {
'1' => {
'Author' => 'Mike',
'idAuthor' => '1'
},
'2' => {
'Author' => 'Cecil',
'idAuthor' => '2'
}
};
<select name="menu_name" tabindex="1">
<option value="HASH(0xa278214)">HASH(0xa278214)</option>
</select><div></div></form>
As you can see from Data::Dumper, I need the drop down menu to show "Mike" and "Cecil" with their values 1 and 2 respectively.
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.