in reply to My globals are visable; but undef'ed

ImHO, it's not a very beautiful way for your files to communicate via global variables, especially if they are set by the main script in the main namespace. And the double-colon form is quite error-prone, which is demonstrated by your problem.

I don't know what exactly you are designing, but maybe the best approach would be an OO constructor, like this:

# Pit.pm package Pit; use strict; sub new { my ($class, $email) = @_; return bless { email => $email, }; } sub printIT { my $this = shift; print '2) ', $this->{email}, "\n"; } # main script: use strict; use Pit; my $pit = Pit->new('me@example.com'); $pit->printIT;

By the way, note the capital "P" in the package name, which is the most common and recommended form to write a package name. And note that the package file needs it's own "use strict" because the line from the main script is not effective there. (Same thing with warnings.)

Replies are listed 'Best First'.
Re^2: My globals are visable; but undef'ed
by massa (Hermit) on Jul 31, 2008 at 20:28 UTC
    Just one correction: don't bless without $class :-)
    sub new { my ($self, $email) = @_; my $class = ref($self) || $self; bless { email => $email }, $class }
    []s, HTH, Massa (κς,πμ,πλ)
      my $class = ref($self) || $self;

      You could throw in another case, just to prevent someone from accidentally calling this method with a $self that happens to evaluate to false:

      my $class = ref($self) || $self || __PACKAGE__;