Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: import doesn't work at runtime?

by Perlbotics (Canon)
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 perusing the Monastery: (12)
As of 2015-07-06 21:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (83 votes), past polls