Search code examples
perlvariablesquotes

perl - help troubleshooting dbi statement that uses double and single quotes


I am trying to figure out why I could not get my variables working properly using Getopt::Std.

For example in this perl DBI statement where the user and password are enclosed in single quotes, everything works fine:

my $dbh = DBI->connect("DBI:mysql:database=$dbsrc;host=$node",'foo-bar','mypw');

But I want to change this statement so that I can pass in a variable for $user, $pw. I am using Getopt::Std; to pass in these values:

my $dbh = DBI->connect("DBI:mysql:database=$dbsrc;host=$node", '$user','$pw');

THIS WORKS NOW:

my $dbh = DBI->connect("DBI:mysql:database=$dbsrc;host=$node", $user,$pw);

I get the following error mesg:

DBI connect('database=;host=hostname','',...) failed:

UPDATED: After input from everybody, the best way to troubleshoot this for me was to see if my vars were being followed through. I basically was passing in the wrong values. So, simply I tested the dbi piece with getopts for those 2 values and nothing else and was able to get it to work.


Solution

  • You aren't showing all of the error message, but the part you do show seems to have an empty value for the user name. Are you sure your $user and $pw are actually set up right at that point in your program?