in reply to Can't use string ("") as a HASH ref while "strict refs"

my $dbh = vol::connect_new($config{'db'}{qw(db_host_name db_name db_user db_pw)});
Hmm, in Perl, that is nonsense. Try something like
my $dbh = vol::connect_new(@{$config{'db'}}{qw(db_host_name db_name db +_user db_pw)});

I can't seem to find anything else wrong with your code, at first sight, so let's just start by trying that out, will you?

Replies are listed 'Best First'.
Re^2: Can't use string ("") as a HASH ref while "strict refs"
by hesco (Deacon) on Nov 26, 2005 at 01:46 UTC
    Bart: Thanks for that. It did not change the error message one iota. Here is the block that defines $config{'db'}. It parses a plain text config.db file which defines four connection variables (host, database, user, password). Similar blocks parse configuration parameters for different elements of the %config hash, which is returned with the Exporter with:
    our %config;
    while (<DB>) { chomp; next if /^\s*\#/; # Allow comments next if /^\s*$/; # Allow blank lines unless (/=/) { # All other lines must look like: KEY + = VAL die "invalid variable assignment in supporters.db: $_"; } my ($key, $val) = split(/\s*=\s*/,$_,2); # Key and value are separ +ated by equals and maybe space $key =~ s/^\s*//; # Strip any leading space from the key # $val =~ s/(\$(\w+))/$config{$2}/g; # Very simple (read: brittle) v +ariable interpolation $val =~ s/ *$//g; # Strip trailing white space from value $config{'db'}{'$key'} = $val; } close DB;
    should this be creating references, instead of simply hash elements? Sorry for delay in responding. I was interrupted by a customer here. Thanks for your help and insight.

      $config{'db'}{'$key'} = $val;
      should be
      $config{'db'}{$key} = $val;
      but I don't think that will fix your error. The error seems to indicate that $config{'db'} was assigned '' or undef. Are you sure both %config are the same variable?

        You wrote: Are you sure both %config are the same variable? Both %config and what? are the same variable?
      A reply falls below the community's threshold of quality. You may see it by logging in.
      Ugh! You're using %config both as input, for "variable values", thus containing strings. as for the output, in $config{'db'}, as a hash ref. My gut feeling tells me this, or something very similar, is the cause of your problem. You may have tried to use $config{'db'} as a string value first, which could well cause your problem.

      Just put your input and output in different variables.