Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by lepetitalbert (Abbot)
on Nov 26, 2005 at 22:21 UTC ( #511956=note: print w/replies, xml ) Need Help??


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

Hello

I had a similar issue and it was caused by a whitespace at the end of the string, as in :

Can't use string ("databasename ")

Try to remove it.

Have a nice day.

"There is only one good, namely knowledge, and only one evil, namely ignorance." Socrates

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

      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
Node Status?
node history
Node Type: note [id://511956]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2020-10-25 19:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (249 votes). Check out past polls.

    Notices?