Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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 meditating upon the Monastery: (12)
As of 2014-09-23 14:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (223 votes), past polls