Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Trouble working with Config::Simple

by parv (Parson)
on Jul 09, 2008 at 03:23 UTC ( [id://696376]=note: print w/replies, xml ) Need Help??


in reply to Re: Trouble working with Config::Simple
in thread Trouble working with Config::Simple

Quite possibly &load_game is being called before $cfg becomes a Config::Simple object.

[...] all of my variables are defined
our @player; our $completed_quests = 0; our $special_item = "none"; our @enemy; our $class = "null"; our $cfg;

From that snippet, I see some of variables being declared but not defined, namely $cfg. Missing also from the snippet are the stages at which &load_game and &Config::Simple::new are being called.

$cfg->read("'$ENV{HOME}/.kenesis'")

What's with two kinds of quotes around file name? Is a file name actually being surrounded by single quotes (on the file system)?

Replies are listed 'Best First'.
Re^3: Trouble working with Config::Simple
by vendion (Scribe) on Jul 11, 2008 at 21:23 UTC
    The variables are defined before everything else, the only reason the the arrays are not defined there is because they are defined later after the class as been selected. the &load_game code comes after everything is defined. The two quotes around the file name $cfg->read("'$ENV{HOME}/.kenesis'") is the only way I was able to get $cfg->read to see the .kenesis file, I'm not sure why I had to though.
    I guess it would be easier for people to review the whole code, I have the project hosted on Google Code and the file can be viewed here. This should help everyone see where everything is at.

      Tell me this: at what point does $cfg get a value from &Config::Simple::new when the program is requested to load a game via load game string coming in from STDIN?

      Between declaration of $cfg variable on line 31 and call to &load_game sub on line 83, $cfg remains undefined. And, what is very first statement of &load_game? It is a call to a(n) (unknown) method read on yet-to-be-defined $cfg. That is the reason for the error message.

      $cfg needs to be defined (even) in &load_game sub before a method could be called on it, much like in the first statement of &new_game sub on line 107. You can do one of at least two things ...

      sub load_game { # No need for separate "$cfg->read( ... )". $cfg = Config::Simple->new( 'file' ); # or ... $cfg = Config::Simple->new; $cfg->read( 'file' ); ... }

      Note that the solution in both forms is already presented in "READING THE CONFIGURATION FILE" section of pod.

        Doing that just leads me into a problem in the next line: Can't call method "param" on an undefined value at kenesis.pl line 92, <STDIN> line1. My Syntax on that line, and the ones to follow, is/are just like the one posted in ACCESSING VALUES section of that documentation. @player = $cfg->param("player"); The configuration file that I am working with is using the "Simple" syntax. Sorry for all of the trouble over this.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-24 03:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found