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.
In reply to Can't call method on an undefined value by Zettai
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |