finddata has asked for the wisdom of the Perl Monks concerning the following question:
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.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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to pass hash site variables into sql connection using perl?
by Anonymous Monk on Mar 30, 2017 at 05:29 UTC | |
by finddata (Sexton) on Mar 30, 2017 at 06:03 UTC | |
by huck (Prior) on Mar 30, 2017 at 06:25 UTC | |
by poj (Abbot) on Mar 30, 2017 at 06:21 UTC | |
|