Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Strange problem with Config::General

by OfficeLinebacker (Chaplain)
on Nov 18, 2013 at 15:04 UTC ( [id://1063112]=perlquestion: print w/replies, xml ) Need Help??

OfficeLinebacker has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, esteemed monks!

I have implemented a solution to use a config file to store the database connection credentials so as to make an app I'm building more portable. I chose Config::General because it's pretty neat. When testing on my local box (Windows 7), when I do

my $cfgfile = 'prodsafety.cfg'; my $conf = Config::General->new($cfgfile); my %config = $conf->getall; foreach my $k (keys %config){ print "$k is $config{$k}." }
I get the expected values. However, on the web host (GoDaddy Linux for those wondering), I get
7/16 is .
and that's it. I've tried playing with line endings but to no avail. Any thoughts?

Replies are listed 'Best First'.
Re: Strange problem with Config::General
by toolic (Bishop) on Nov 18, 2013 at 15:22 UTC

    Tip #4 from the Basic debugging checklist (Data::Dumper):

    my %config = $conf->getall; use Data::Dumper; print Dumper(\%config);

    The 7/16 looks like perldata...

    If you evaluate a hash in scalar context, it returns false if the hash is empty. If there are any key/value pairs, it returns true; more precisely, the value returned is a string consisting of the number of used buckets and the number of allocated buckets, separated by a slash. This is pretty much useful only to find out whether Perl's internal hashing algorithm is performing poorly on your data set. For example, you stick 10,000 things in a hash, but evaluating %HASH in scalar context reveals "1/16" , which means only one out of sixteen buckets has been touched, and presumably contains all 10,000 of your items. This isn't supposed to happen. If a tied hash is evaluated in scalar context, the SCALAR method is called (with a fallback to FIRSTKEY ).
      Hi. I agree, it looks like perldata. I tried Data:Dumping the value and I got $VAR1 = { '7/16' => undef }; So is that a dead end?

        Try dumping your $conf object just to be sure the problem isn't on that side (I really don't think so). You could also try making list context even more explicit with : my (%config,) = ($conf->getall,); # Now that's overdoing it and see if it changes anything.

        If you can't get any further, try to reduce your program as much as possible until you reach the minimum conditions to reproduce the defect. And tell us on which versions of Perl you work in both cases

Re: Strange problem with Config::General
by Eily (Monsignor) on Nov 18, 2013 at 15:20 UTC

    Are you running the exact same code in both cases?. Your output looks like you called $conf->getall in scalar context before assigning the result to %config. Something roughly like : my %config = scalar $cong->getall;, except the problem is probably far less obvious. But then you should have two warnings if they are on:

    Odd number of elements in hash assignment at - line X. Use of uninitialized value in print at - line X.

      Hi. Yes I have warnings on and the code is identical. Thanks.

        With warnings activated there should have been at least the second one(and I don't see how the first could have been skipped). Are there other warnings you did not see or forgot to tell us about?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-03-19 08:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found