Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^5: more fun w/ HASh ref's

by hesco (Deacon)
on Nov 26, 2005 at 23:11 UTC ( [id://511958]=note: print w/replies, xml ) Need Help??


in reply to Re^4: more fun w/ HASh ref's
in thread more fun w/ HASh ref's

That is among the great mysteries to me. The supporters_conf.pm block which builds this value, includes the following lines:

$val =~ s/ *$//g; # Strip trailing white space from value $config{'db'}{"$key"} = $val; $config{"$key"} = $val;

When I use $config{'db_name'} it works. When I use the $config{'db'}{'db_name'}, it gives me the HASH ref error. Seems like that string substitution ought to clean out that extraneous space. I'm not sure why its not.

-- Hugh

Replies are listed 'Best First'.
Re^6: more fun w/ HASh ref's
by dragonchild (Archbishop) on Nov 27, 2005 at 00:33 UTC
    Try s/\s*$//; instead of your regex. It might not be a literal space - it might be any one of a number of whitespace characters.

    Plus, the problem isn't with $val, it's with $key. Try printing out $key in each iteration with single-quotes around it.


    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
      Thank you for your time, kind monk.

      I've tried \s*, \S* and \ * in string substitutions in an effort to lose that trailing space. I have now intoduced a line which reads:

      print STDERR "|$host|, |$db|, |$user|, |$pw|";

      to determine where that space might be introduced. In Main::, when I define $db as $config{'db_name'}, I get the right value in the log. When I define $db as $config{'db}{'db_name'}, it throws the HASH ref error (as a Fatals to Browser message) and bombs out before it gets to my print STDERR debug statement.

      As you can see from the code I posted at http://perlmonks.org/?node_id=511957, my supporters_conf.pm module includes a while <DB> block which includes:

      my ($key, $val) = split(/\s*=\s*/,$_,2); $key =~ s/^\s*//; $val =~ s/ *$//g; # also tried \s* and \S*, as well $config{'db'}{"$key"} = $val; $config{"$key"} = $val;
      So I'm thinking this has something to do with the $config{'db'}{'db_name'} piece and not with the value assigned to this hash element.

      -- Hugh

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://511958]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-25 05:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found