http://www.perlmonks.org?node_id=923351

sarvan has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I have a file called "porter.pm". This is a perl module which i am trying to use in my code. So, in order to use it, i need to add this porter.pm to my @INC path.. But, i failed to do that. I need help. Can anyone let me know.. Thanks.

Replies are listed 'Best First'.
Re: How to add a file to @INC path in perl
by ikegami (Pope) on Aug 31, 2011 at 05:34 UTC

    Files aren't added to @INC, directories are. For example, if Porter.pm was located in /home/ikegami/perl5/lib, I could do

    use lib "/home/ikegami/perl5/lib"; use Porter;

    Keep in mind that if the package is My::Porter you, should place the file in /home/ikegami/perl5/lib/My and use

    use lib "/home/ikegami/perl5/lib"; use My::Porter;


      with -I option , you can add files to @INC at run time.
      #!/usr/bin/perl -I/path-to-new-library/


      Regrds,
      Prafull
        That's actually before compile-time. Good thing too, because it would be useless to change @INC at run time.

      I generally do much the same, but work from a relative path using the FindBin module. FindBin will give you the directory the script is running from. My additional libs are generally in a folder relative to this location as below.

      use FindBin; use lib $FindBin::Bin . '/lib';