I am trying to populate the drop-down list from mysql data and got the solution from Populating a Drop-Down list using DBI and How do I get selected value from drop down box in Perl CGI
I have following code:
#!/usr/bin/perl
use warnings;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use DBI;
use Data::Dumper;
print "Content-type: text/html\n\n";
my $dbh = DBI->connect();
my @tables=$dbh->selectcol_arrayref('select TABLE_NAME from 1009_table_list order by TABLE_NAME');
print Dumper@tables; #this dumper is giving results
print qq[
<!DOCTYPE html>
<html>
<head></head>
<body>
<form id="upload-form"><table>
<tr><td>Table Name:</td><td><select name="tbname">
];
print Dumper@tables; # this dumper is not printing anything
foreach my $table(@tables)
{
print qq "<option value=\"$table\">" . $table . "</option>";
}
print qq[
</select>
</td></tr>
</table></form></body>
</html>
];
At second comment in code I am not able to get the value of @tables for the drop-list. Why?