I like to connect multiple hash variables with mysql database connection?How can i do it.Suppose if have four database names in hash i want to pass those database names as variables for database connection .How can i do it?
use strict;
use warnings;
use Getopt::Long;
my $site;
GetOptions("site=s" => \$site)
or die "Error in command line arguments\n";
if($site eq ''){
$site = 'site1';
}
defined $site
or die "usage: $0 site_name\n";
my %site_map = (
site1 => [ qw(a_site1_current) ],
site2 => [ qw(a_site2_current) ],
site3 => [ qw(a_site3_current) ],
);
sub connect {
$host = "dam.sd.aog.com";
$database = "a_$site_map\_current" ;
$user = "ad" ;
$pw = "123";
my $dsn = "DBI:mysql:host=$host";
my $dbh = DBI->connect($dsn, $user, $pw) ||
die "ERROR: can't connect to database server\n";
return $dbh;
}
sub ShowContents {
my @arr = @{$site_map{$site}};
#print @arr;
}
I had tried the above manner to pass all hash table site names into the database connection but my code is not working.Help me to fix the issue.Thanks for any help in advance.
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.