3

I want to set a path in @INC, as script is failing to locate perl module. Requirement is that , i cannot include the module path in the script directly. So , i am thinking to add module path directly in @INC. Is there a way i can do that.

I have tried to edit ~/.bash_profile , ~/.bashrc as well. But its not adding the path in @INC.

Mudassar Rana
  • 27
  • 1
  • 3

4 Answers4

3

There are various ways:

  • call as perl -Ipath script.pl
  • call as PERL5OPT=path script.pl
  • globally set export PERL5OPT=path in .profile or PERL5OPT=path in .pam_environment (affects other scripts too)
1

If you've modified ~/.bashrc and it hasn't added it to your environment, then you are probably adding it to your PATH. The best way to do this is to use the PERL5LIB environment variable.

If you want to do this at the start of each shell session no matter what is going on, add the following line to ~/.bashrc (assuming that the shell is bash) and the source the script or start a new shell session.

export PERL5LIB=/path/to/module

If you want to do it only in that script, add the following line after the shebang:

use lib '/path/to/module';

If you just want to do it as fast as possible, run the script with perl -I

perl -I /path/to/module script.pl

All of these methods will prepend the directory containing the module to @INC

Nasir Riley
  • 11,422
0

I found the simple soultion of it.

push(@INC,/path) or unshift(@INC,'/path)

Second method : use lib "/path" in file itself.

Mudassar Rana
  • 27
  • 1
  • 3
0

Make the first line of calling .pl, e.g.:

use lib ".";
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255