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

Hi,

I created two of the bunch of modules I wanted to create. I decided to keep them in a subdirectory and access using Module::Submodule format.

Somehow it is not working for me. I get the error message "Undefined subroutine &main::method1 called at program.pl line 12.

The way I organised this is

Main program: ~/perl/program.pl

use strict; use warnings; use lib '/home/my_uname/perl/lib'; use Module::Submodule1; method1 (args); method2 (args);
The Modules are in the directory "~/perl/lib/Module" directory and have the following

Submodule1.pm: (Submodule2.pm is similar)

package Submodule1; use strict; use warnings; use Exporter; our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); @ISA = qw(Exporter); @EXPORT = qw(method1 method2); sub method1 { ... } sub method2 { ... } 1; __END__

It works if I copy the Submodule1.pm and Submodule2.pm files to ~/perl/lib/ directory.

These are not OO Modules -they are just subroutines. I am doing this just to keep all the subroutines of a particular category in a module. And of course all these Submodules are for an application (Module).

Also, I do not have root privileges to keep these modules in the /usr/bin/perl/lib (??) directory

Any help is appreciated

Replies are listed 'Best First'.
Re: Creating a module in a directory to accomplish ::
by friedo (Prior) on Aug 29, 2005 at 20:42 UTC
    You're useing Module::Submodule1, but your package declaration just says Submodule1. The use statement succeeds because it finds lib/Module/Submodule1.pm but when it compiles that code, it sees the package Submodule1 instead of Module::Submodule1. Thus, your module's import method (inherrited from Exporter) is never called, and you don't import the functions.

    Try changing your package declaration to package Module::Submodule1; and it should work.

      Thanks very much... it worked!

      Believe me, I have been struggling with this for couple of months now..

      Thanks once again