Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: import doesn't work at runtime?

by Perlbotics (Abbot)
on Nov 11, 2011 at 22:09 UTC ( #937678=note: print w/ replies, xml ) Need Help??


in reply to import doesn't work at runtime?

You're missing some parenthesis and some strictures to explain the problem. Without parens:

perl -e 'use strict; use warnings; require MyModule; MyModule->import( +qw(frobnicate munge)); frobnicate; munge; ' Bareword "frobnicate" not allowed while "strict subs" in use at -e lin +e 1. Bareword "munge" not allowed while "strict subs" in use at -e line 1. Execution of -e aborted due to compilation errors.
With:
perl -e 'use strict; use warnings; require MyModule; MyModule->import( +qw(frobnicate munge)); frobnicate(); munge(); ' frobnicated! munged!
With parens, Perl knows at compile time that frobnicate()/munge() are subroutines and that Perl can deal with them later at runtime. So, the following also works, but changes the semantics a bit (first argument is "MyModule") - Perl still detects the subroutine invocation (w/o parens):
perl -e 'use strict; use warnings; require MyModule; MyModule->import( +qw(frobnicate munge)); MyModule->frobnicate; MyModule->munge; ' frobnicated! munged!


Comment on Re: import doesn't work at runtime?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://937678]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2014-07-26 18:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (178 votes), past polls