Zettai has asked for the wisdom of the Perl Monks concerning the following question:
I apologise for the duplicate post. I have read the other posts similar to this and my lack of Perl understanding has finally gotten me into trouble.
My project is separated into different files and different directories.
An example structure is as follows:
main.pl:
#!/camelbox/bin/perl package main; use strict; use Gtk2 -init; use Log::Log4perl; # Init Logger from config file. Log::Log4perl::init_and_watch( 'log\root-logger.conf', 30 ); our $logger = Log::Log4perl->get_logger; # Run main loop. Gtk2->main;
I then have a number of packages using the logger from main:
Subdir/Foo.pm
package Foo; $main::logger->debug("Here is a debug message in Foo."); 1;
Subdir/Bar.pm
package Bar; $main::logger->debug("Here is a debug message in Bar."); 1;
Subdir/Baz.pm
package Baz; $main::logger->debug("Here is a debug message in Baz."); 1;
As an example in my project, Foo and Baz are both able to use $main::logger->debug or $main::logger->error but for some reason Bar returns the error message:
Can't call method "error" on an undefined value at...or
Can't call method "debug" on an undefined value at...What could be some of the reasons that only package Bar cannot 'see' or use the $main::logger method? In my project there are a number of other files in the same directory that contains Bar all of which are able to use $main::logger->debug/error without any problems.
Thank you for any suggestions.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Can't call method on an undefined value
by andal (Hermit) on Nov 16, 2011 at 08:37 UTC | |
Re: Can't call method on an undefined value
by Anonymous Monk on Nov 15, 2011 at 23:57 UTC | |
by Zettai (Acolyte) on Nov 16, 2011 at 03:46 UTC | |
by remiah (Hermit) on Nov 16, 2011 at 07:23 UTC | |
Re: Can't call method on an undefined value
by johnny_carlos (Scribe) on Nov 15, 2011 at 23:13 UTC | |
Re: Can't call method on an undefined value
by anneli (Pilgrim) on Nov 16, 2011 at 00:46 UTC | |
Re: Can't call method on an undefined value
by thargas (Deacon) on Nov 16, 2011 at 13:34 UTC |