BadHarry has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
A long time ago I wrote a module which seems to work fine. It is a bit like this, but does more.
# OddEffectOfImportTest.pm v1 package OddEffectOfImportTest; use Exporter; @ISA = qw(Exporter); @EXPORT = qw($OddEffectOfImportTest); our $OddEffectOfImportTest = 6.28; 1;
... and using it like this is fine.
#!/usr/bin/perl # OddEffectOfImportTest v1 use strict; use OddEffectOfImportTest; print "$OddEffectOfImportTest\n";
the point being that $OddEffectOfImportTest doesn't have a package name.
Now I've decided it would be useful to help it initalise, so I can use it thus:
#!/usr/bin/perl # OddEffectOfImportTest v2 use strict; use OddEffectOfImportTest goreallyfast => 1; print "$OddEffectOfImportTest\n";
but when I add "sub import{}" to the module:
# OddEffectOfImportTest.pm v2 package OddEffectOfImportTest; use Exporter; @ISA = qw(Exporter); @EXPORT = qw($OddEffectOfImportTest); our $OddEffectOfImportTest = 6.28; sub import {} 1;
..., without any other changes, I now I get
Global symbol "$OddEffectOfImportTest" requires explicit package name +at ./OddEffectOfImportTest line 5. Execution of ./OddEffectOfImportTest aborted due to compilation errors +.
Lots of my scripts use this module and I rather not track down and change them all if possible.
Threads 277141 and 569862 looked related but not close enough (for me to understand, at least.
Thanks for any help.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Adding "sub import{}" to my module makes global symbols require an explicit package name
by Corion (Patriarch) on Sep 28, 2010 at 16:21 UTC | |
|
Re: Adding "sub import{}" to my module makes global symbols require an explicit package name
by afoken (Chancellor) on Sep 28, 2010 at 21:04 UTC | |
by BadHarry (Initiate) on Sep 29, 2010 at 09:22 UTC |