Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

G'day Hugh.

Might I suggest, for starters, that writing your own config parsing code is probably a mistake already? While I'm certain we can help you to get it working, you might find an existing module such as Config::IniHash, Config::Tiny or Config::General a better solution, especially in the long term. For your case I'd probably recommend Config::IniHash.

When is the error occuring? During compilation? During runtime? Can you compile the code as follows (outside of a CGI session)?

perl -cw yourcode.cgi

If it's happening during runtime, is it happening when you read in the config file, or when you later try to access it? If it's when you later try to access it, use Data::Dumper to have a look inside the config hash. Is it behaving as you'd expect?

# Generate config hash then... use Data::Dumper; print Dumper %config;

Try isolating the problem. Write a new program which reads in the config data and then accesses it as you want to. Try to make it as simple as possible, perhaps as below:

# Config_reader.pm package Config_reader; use base Exporter; use strict; use warnings; # etc 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; ## test.pl use Config_reader qw/%config/; use Data::Dumper \%config; my($host) = $config{db}{db_host_name}; my($db) = $config{db}{db_name }; my($user) = $config{db}{db_user }; my($pw) = $config{db}{db_pw };

If that doesn't work, then you've got something we can more easily help you debug. If it does work, then chances are that your problem is not actually where you think it is.

Either way, I strongly recommend you have a look at the already existing configuration modules.

All the very best,

jarich

In reply to Re: more fun w/ HASh ref's by jarich
in thread 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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (None)
    As of 2024-04-25 01:31 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found