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:

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.
on the following line:

my($host) = $config{'db'}{'db_host_name'};
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.

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:

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;
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.

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


In reply to more fun w/ HASh ref's by hesco

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.