Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

How to add a file to @INC path in perl

by sarvan (Sexton)
on Aug 31, 2011 at 05:28 UTC ( [id://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 (Patriarch) 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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-03-28 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found