jcpunk has asked for the wisdom of the Perl Monks concerning the following question:

I have a few tools that use a shared library, and just decided to add a fun little module to them. I was wondering, since the third line is 'require ./library;' can I just put my use statement inside of 'library' and use the module inside of the program itself or must I 'use' it inside of both to use its functions inside of both?

jcpunk
all code is tested, and doesn't work so there :p (varient on common PM sig for my own ammusment)

Replies are listed 'Best First'.
Re: A question of module scope
by BUU (Prior) on Apr 25, 2004 at 07:21 UTC
    I have no idea what you're really asking, but when you do "use module;" that module will only export it's functions to the callers namespace. So the functions from that module will only be available, in the unqualified form, to whichever package directly uses that module. Note you can still access any function you want via the "Package::Function()" syntax.
Re: A question of module scope
by dragonchild (Archbishop) on Apr 25, 2004 at 14:48 UTC
    If I understand your question correctly, library is a file which contains a bunch of Perl statements and functions. You also have a bunch of Perl scripts that use library. You have another module that you want to make available to both library and your Perl scripts.

    Part of what confused the earlier respondents is that Perl libraries usually have the extension ".pm". Many older applications, especially those from Perl4, don't. *shrugs*

    The short answer is that you have to put your use statement within every package that you wish to have the symbols available.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

Re: A question of module scope
by Steve_p (Priest) on Apr 25, 2004 at 14:19 UTC

    I'm a bit confused. When you use the term "shared library", are you talking about a compiled library on your system, such as a ".a" or ".dll" file? Perl modules are modules, no matter if they are "shared" or not.

    Also, since you provided no source with your question, my answer is, "It depends." If the two modules are Exporters and the functions you want to call are all exported through to your program, then, yes, you would only need to use your funlittlemodule. Otherwise, you may need both modules. Unfortunately, I have so little to go on, I can't say for sure.

    In the meantime, post some code and read perldoc perlmod.