in reply to Re^2: Reading host from defaults file with DBD::mysql
in thread Reading host from defaults file with DBD::mysql

Have you gone through Basic debugging checklist? Sounds like you've now done part (using the debugger), but maybe not everything: Does your $opts{defaults} really contain what you think it does when it enters the sub you showed? If not, then the problem lies outside of what you've shown. If it does contain what you think it should, then give us a security-redacted version of $opt{defaults}, because we cannot debug your logic in that sub without knowing what's there. See also SSCCE, How to ask better questions using Test::More and sample data, and How do I change/delete my post?


edit: add "everything": I had intended the "but maybe not: ..." to be one logical thought, separate from "you've now done part"... but when re-reading, it looked more like I was saying OP hadn't done even the running-the-debugger, which was not what I meant. sorry. /edit

  • Comment on Re^3: Reading host from defaults file with DBD::mysql

Replies are listed 'Best First'.
Re^4: Reading host from defaults file with DBD::mysql
by Llew_Llaw_Gyffes (Scribe) on Jan 31, 2019 at 19:01 UTC

    Actually, I think I've identified the problem. It appears it is working as long as there are NO SPACES in the setting lines in the MySQL defaults file. If there are spaces around the "=", the setting is not read.

    So a defaults file containing:

    [mysql] user=fred host=mydb.localdomain password=BANANA

    works, but:

    [mysql] user = fred host = mydb.localdomain password = BANANA

    does not.

      What module did you use for reading/parsing your INI file? Config::Tiny? Config::Simple? Config::INI? Something else? Or did you roll your own?

      For example, Config::Tiny handles spaces around the equals just fine:

      #!/usr/bin/perl -l use warnings; use strict; use Config::Tiny; my $ini_string = <<"EOINI"; a=nospace b = space [GROUP1] c=nospace d = space EOINI my $cfg = Config::Tiny->read_string($ini_string); use Data::Dumper; $Data::Dumper::Indent = 0; print Dumper $cfg; __END__ __OUTPUT__ $VAR1 = bless( {'_' => {'a' => 'nospace','b' => 'space'},'GROUP1' => { +'d' => 'space','c' => 'nospace'}}, 'Config::Tiny' );

      I don't have the other two installed, but Config::INI claims to handle spaces around the equals, and Config::Simple's claim of "whitespace support" implies to me that it might

        The file, as part of $dsn string, is passed to DBI->connect method. I failed to find in (top level) DBI & DBD::mysql sources a point where it would have been parsed.

      Seriously? Are you sure you had not changed anything other than spaces around "=" in the mysql defaults file?