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

Hi
i have a file callModule.pl located in folder rose on the desktop of windows xp,
i want this file to call a module SomeModule.pm located in folder myModules inside the folder rose. i can't make it to work, it is working when the module in the same folder of the callModule.pl
here is my experiment:
callModule.pl:
use strict; use warnings; use Cwd; my $dir = getcwd; my $file = $dir . "/myModules/" . "SomeModule.pm"; use $file; print "I am in the main package\n"; SomeModule::func();
the module SomeModule.pm:
package SomeModule; use strict; use warnings; sub func { print "I am in func in SomeModule\n"; } 1;
thank you

Replies are listed 'Best First'.
Re: calling a module in a folder within current directory
by shmem (Chancellor) on Dec 07, 2009 at 14:13 UTC
    SomeModule.pm located in folder myModules

    ...will be loaded via

    use myModules::SomeModule;

    The module itself needs to state this namespace:

    package myModules::SomeModule;

    Alternatively, you have to extend perl's search path (in callModule.pl):

    use lib "rose/myModules";

    That way perl will search the folder "rose/myModules" for "SomeModule.pm" .

    The statement use $file; is illegal. The documentation for use states: "(...) Module must be a bareword."