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

Re: Imported subroutines

by Laurent_R (Monsignor)
on Sep 16, 2013 at 21:50 UTC ( #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?

Comment on Re: Imported subroutines
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 (Sage) 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:


    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?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2015-11-26 16:00 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (701 votes), past polls