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

Dear Monks, I'm confused how main imports symbols from a package. My main package includes a path to my modules with
use lib "/home/me/lib/perl5";
My module, common.pm, sits in directory Rose under perl5. It starts off like
common.pm sub return_address{ print "rose garden"; } ... 1;
Inside main, return_address is called with
common::return_address();
but not with
Rose::common::return_address();
for then the subroutine is undefined. So I'm doing something wrong; tachyon uses this last form in "Simple Module Tutorial" for example. Besides, what about my other directory of modules, Tulip which also contains a package common.pm. How do I call it from main? Begging your pardon for my errors and thanking you for your advice, RW

Replies are listed 'Best First'.
Re: modules and namespace
by chromatic (Archbishop) on Nov 20, 2003 at 21:59 UTC

    The path to a module file only affects what you use to load it, and that in turn depends on what's in @INC. Within the file, you can declare as many packages as you like and give them whatever names you like.

    For consistency, paths and module names often match. This is not required by Perl, only good sense.

      I think I understand. Even the Lectoids needed different last names, not just different addresses? For possible future reference: NO! "use" just inserts code with checks (cf. perlfaq8) and a "package" declaration changes the namespace, so two modules may have the same name with subs of the same name but live in different directories; it is the most recently declared package that provides the code.