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

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?

Replies are listed 'Best First'.
Re^7: more fun w/ HASh ref's
by hesco (Deacon) on Nov 27, 2005 at 02:07 UTC
    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