0

In some perl programs, I see they begin with

BEGIN
{
push(@INC, '/home/usr1/Modules');
}

I would like to know what does this part intend to do?

user297850
  • 7,705
  • 17
  • 54
  • 76
  • 2
    possible duplicate of [How is Perl's @INC constructed? (aka What are all the ways of affecting where Perl modules are searched for?)](http://stackoverflow.com/questions/2526804/how-is-perls-inc-constructed-aka-what-are-all-the-ways-of-affecting-where-pe) – DVK Feb 16 '12 at 16:05

1 Answers1

5

This ensures that any perl modules which are contained in the directory /home/usr1/Modules will be available for usage.

When one types use ModuleName, Perl will search every directory in @INC for the file ModuleName.pm.

asf107
  • 1,118
  • 7
  • 22
  • 3
    but why not simply: use lib '/my/path' ? Available in core since 1995.. (http://perldoc.perl.org/lib.html) – Øyvind Skaar Feb 16 '12 at 15:03
  • 1
    yeah, that'd work too. Honestly, all my modules are in place by setting the environment variable `PERL5LIB` in my bash profile, so neither of these things are truly necessary – asf107 Feb 16 '12 at 15:08
  • 2
    @asf107, `PERL5LIB` is ignored in taint mode, which may never be an issue for you but can be a issue in secure environments. – Ven'Tatsu Feb 16 '12 at 15:46