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

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.

Replies are listed 'Best First'.
Re^3: Can't use string ("") as a HASH ref while "strict refs"
by ikegami (Patriarch) on Nov 26, 2005 at 03:27 UTC

    $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?

        The %config in the first snippet and %config in the second snippet.

        • Maybe they are both package (our) variables, but in different packages.
        • Maybe one is a package (our) variable, and the other is a lexical (my) variable.
        • Maybe they are both lexical (my) variables, but different lexical varibbles (i.e. in different scopes). [There's an our in one of the snippets.]
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^3: Can't use string ("") as a HASH ref while "strict refs"
by bart (Canon) on Nov 26, 2005 at 09:16 UTC
    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.