gdave has asked for the wisdom of the Perl Monks concerning the following question:
so it seems I can only import() from MyModule at compile time ('use' or BEGIN') but not at runtime. Here's my test case:
my module (MyModule.pm):
package MyModule; use Exporter(); our @ISA = qw(Exporter); @EXPORT_OK = qw(munge frobnicate); sub frobnicate { print "frobnicated!\n"; } sub munge { print "munged!\n"; }
When I call it from a script, this works (meaning I see the output from the print statements):
use MyModule qw(frobnicate munge); frobnicate; munge;
output is:
frobnicated! munged!
and this works (same output)
BEGIN { require MyModule; MyModule->import( qw(frobnicate munge) ); } frobnicate; munge;
but this does not (no output)
require MyModule; MyModule->import( qw(frobnicate munge) ); frobnicate; munge;
This seems to me to imply that I can only import at compile time, not at run-time.
Am I missing something?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: import doesn't work at runtime?
by johnny_carlos (Scribe) on Nov 11, 2011 at 21:56 UTC | |
by gdave (Novice) on Nov 11, 2011 at 22:08 UTC | |
by TomDLux (Vicar) on Nov 12, 2011 at 18:59 UTC | |
|
Re: import doesn't work at runtime?
by bluescreen (Friar) on Nov 11, 2011 at 22:03 UTC | |
|
Re: import doesn't work at runtime?
by CountZero (Bishop) on Nov 11, 2011 at 22:22 UTC | |
|
Re: import doesn't work at runtime?
by Perlbotics (Archbishop) on Nov 11, 2011 at 22:09 UTC |