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 | |
by chromatic (Archbishop) on Aug 01, 2008 at 05:38 UTC |