I am accepting User Input in an If-Else block. Check Code:
if ( $svr == 1 ) {
print "Enter Datbase Name\n";
my $db = <>;
chomp($db);
} elsif ( $svr == 2 ) {
print "Enter Data Source Name (DSN)\n";
my $db = <>;
chomp($db);
}
When I am referring to $db in a later statement, I am getting the following error:
“Use of uninitialized value $db”
This is the statement in which I am using $db that is causing the error:
my $data_source = 'DBI:mysql:' . $db . ':' . $host;
Please help
The first
$dbis scoped to the “then” block, and teh second$dbis scoped to the “else” block. You need declare the$dbvar before theif.