Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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 "". 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 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 (Patriarch) on Aug 31, 2011 at 05:34 UTC

    Files aren't added to @INC, directories are. For example, if 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/

        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?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2023-09-26 20:14 GMT
Find Nodes?
    Voting Booth?

    No recent polls found