hesco has asked for the wisdom of the Perl Monks concerning the following question:
OK. In an attempt to isolate the issue, I have rewritten my call to the connect_new subroutine I wrote about earlier. This time it errors out before I get to call that subroutine, eliminating it as a potential source of this issue.
Now my error reads, very much as it did yesterday, only with a new line number:
on the following line:Can't use string ("databasename ") as a HASH ref while "strict refs" i +n use at /usr/lib/cgi-bin/bc/supporters.cgi line 264.
pointing out an additional issue, namely that somehow my database name (still with that annoying trailing space) has somehow been mis-assigned to my db_host_name key in the $config->{'db'} hash.my($host) = $config{'db'}{'db_host_name'};
Since this is a hash slice to scalar assignment, it eliminates me having to wrap my head around the proper syntax for converting multiple element hash slices into arrays.
Again, the block which defines the $config->{'db'} hash reads as follows:
I assign $val to two different elements of the hash here. As an experiment. $config{"$key"} properly passes the values (I suspect), as the .cgi page resolves without error. But $config{'db'}{"$key"} does not, resulting in the error described above.while (<DB>) { chomp; next if /^\s*\#/; next if /^\s*$/; unless (/=/) { die "invalid variable assignment in supporters.db: $_"; } my ($key, $val) = split(/\s*=\s*/,$_,2); $key =~ s/^\s*//; $val =~ s/ *$//g; $config{'db'}{"$key"} = $val; $config{"$key"} = $val; } close DB;
So I guess I can make my script work. But I was hoping to tighten up the code some and do in one line, what I have been doing in five. And I'm still confused about this HASH ref error. What does that mean? Where is this explained for me? How do I avoid it?
All help appreciated.
-- Hugh
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: more fun w/ HASh ref's
by merlyn (Sage) on Nov 26, 2005 at 20:50 UTC | |
by hesco (Deacon) on Nov 26, 2005 at 21:16 UTC | |
by merlyn (Sage) on Nov 26, 2005 at 21:22 UTC | |
by lepetitalbert (Abbot) on Nov 26, 2005 at 22:21 UTC | |
by hesco (Deacon) on Nov 26, 2005 at 23:11 UTC | |
| |
by hesco (Deacon) on Nov 26, 2005 at 22:53 UTC | |
Re: more fun w/ HASh ref's
by jarich (Curate) on Nov 27, 2005 at 14:05 UTC | |
by hesco (Deacon) on Dec 01, 2005 at 01:04 UTC | |
by jarich (Curate) on Dec 12, 2005 at 02:48 UTC |
Back to
Seekers of Perl Wisdom