Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://937678]
help
Chatterbox?
[erix]: (culprits often are upstream of db of course)
[Corion]: Ah, how I missed it. After some years, I revisit slashdot on a click-bait link, and it provides the usual humor instantly: "I didn't know Drupal had rules for sex. It must be a plug-in"
[Corion]: erix: This is not for sybase, but for the input data files, resp. their contents.

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2017-03-28 09:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (328 votes). Check out past polls.