Take the 2-minute tour ×

I have the following file structure:

| |___FooController.pm
| |___Foo.pm
| |___BarUtils.pm

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.

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

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:

share|improve this answer
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 –  aljndrrr Mar 4 '12 at 2:22
add comment

Your Answer


