Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

How to add a file to @INC path in perl

by sarvan (Sexton)
on Aug 31, 2011 at 05:28 UTC ( #923351=perlquestion: print w/replies, xml ) Need Help??

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';

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://923351]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2020-10-24 07:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (242 votes). Check out past polls.

    Notices?