0

I have the following file structure:

|_controllers
| |___FooController.pm
|_models
| |___Foo.pm
|_utils
| |___BarUtils.pm
|_foobar.do

I want to know how can I import the modules between files, let say that I want to use Foo.pm on FooControllers.pm or use BarUtils.pm on foobar.do . When I have the files on the same directories I just do

use Foo;

But in this case I cannot figure out how to do it.

tchrist
  • 78,834
  • 30
  • 123
  • 180
JohnnyAce
  • 3,569
  • 9
  • 37
  • 59

1 Answers1

5

You need to make sure that:

  • The parent directory (the one that contains controllers etc..) is in @INC

  • The modules would then be named:

    use controllers::FooController;
    use models::Foo;
    

The exact rationale for how and why this works (as well as @INC details) can be found on SO:

Community
  • 1
  • 1
DVK
  • 126,886
  • 32
  • 213
  • 327
  • Thanks, I also found that require './utils/Connection.pm'; works but you'll have to set all the routes manually so it's better to add the path to the %INC – JohnnyAce Mar 04 '12 at 02:22