Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Imported subroutines

by Laurent_R (Canon)
on Sep 16, 2013 at 21:50 UTC ( [id://1054338]=note: print w/replies, xml ) Need Help??


in reply to Imported subroutines

I may be wrong, but my understanding is that when you use or require a module, Perl is compiling the whole module anyway, including the subroutines which are not exported, so that the only difference between exporting or not exporting a function (putting its name in @EXPORT or @EXPORT_OK) would really be updating the program namespace, which probably is not measurable. The fact that you don't export a subroutine does not mean that you don't use it, it only means that it is not intended to be used directly by the main program, but it may very well be used internally by other functions of the same module. Is this view wrong? Am I missing something?

Replies are listed 'Best First'.
Re^2: Imported subroutines
by sundialsvc4 (Abbot) on Sep 17, 2013 at 01:48 UTC

    No, I think that you are exactly correct.   The module will be compiled, regardless, if not done already.   Then, any name in @EXPORT will be added to the global namespace.   If you provide a list of routines in your use statement, they must be in @EXPORT_OK.

    Nothing will lead to any sort of performance problem.   Everything goes through a one-time “compile (on the fly)” process and, once done, never happens again (AFAIK) for the duration of the run.   If there is a performance issue in this app, “red herring ... look elsewhere.”

Re^2: Imported subroutines
by GrandFather (Saint) on Sep 18, 2013 at 03:31 UTC

    I almost never export anything from modules I write. I almost always:

    use Wibble qw();

    when I use modules. I means I have to:

    Wibble::Wobble();

    when I need to call Wobble(), but at least I know where Wobble() lives that way even minutes, or months, after I wrote the code.

    Using OO largely avoids the name space pollution problem that these measures seek to avoid without cluttering the code with explicit name space references.

    True laziness is hard work

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-19 21:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found