Hi Monks,

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.