in reply to Including my own modules

As well as the other comments monks have given, I thought i should mention that you should always use strict and use warnings. You might also want to use diagnostics which will give you more verbose warnings, and can often help identify the cause of your errors.

You should also make sure your script knows where your mods live, if it is not in with all the others. This is a good time to use a BEGIN{} block and lib:

use strict; use warnings; BEGIN{ use lib '/path/to/your/homemade/modules/'; } ## now try use Module::Try::Error;

There is no point in doing this if your modules are already somewhere that perl knows about (the places it looks for modules are held in the special variable @INC). HTH.

Just a something something...

Replies are listed 'Best First'.
Re^2: Including my own modules
by paixaop (Novice) on Dec 17, 2009 at 13:13 UTC

    Thank you guys for the quick replies. I always do "use strict" but hardly ever "use warnings", so I will start using it as well.

    I was using the lib as well but I thought that it was not very elegant solution. What is your advice for when you create a distribution that is installed by other users? By then the modules will live where perl can find them and the lib statement is no longer needed.

    Should I use lib /my/svn/work/dir while in development and remove it afterwards?

    what are the best practices?

    Once again thank you in advance for all your wisdom.

      By then the modules will live where perl can find them and the lib statement is no longer needed.

      Should I use lib /my/svn/work/dir while in development and remove it afterwards?

      In this case you could also set the environment variable PERL5LIB to tell Perl about the additional lib directory in the development environment. This way you wouldn't need any use lib statement at all...

      The general idea is

      dev.pl

      use lib '/my/svn/work/dir'; use MySweetApp; MySweetApp->run();
      prod.pl
      use lib '/production/dir'; use MySweetApp; MySweetApp->run();
      cust.pl
      use lib '/production/dir'; use MySweetApp; MySweetApp->new('notdefault.config')->run();
Re^2: Including my own modules
by Anonymous Monk on Dec 17, 2009 at 10:15 UTC
    BEGIN isn't necessary, use happens at BEGIN time