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

Re: How to add a file to @INC path in perl

by ikegami (Pope)
on Aug 31, 2011 at 05:34 UTC ( #923353=note: print w/replies, xml ) Need Help??


in reply to How to add a file to @INC path in perl

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;

Replies are listed 'Best First'.
Re^2: How to add a file to @INC path in perl
by prafulltc (Acolyte) on Aug 31, 2011 at 07:24 UTC


    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 change @INC at run-time all the time.

        What you're probably confused about is that 'use Some::Module' normally happens at compile-time (actually it happens in a virtual BEGIN block) and that is how most people interact with @INC. However, you can defer useing modules by doing it in a string-eval, or you can use require, or do.

        And there are all kinds of evil tricks you can play by putting code-refs into @INC.

Re^2: How to add a file to @INC path in perl
by Kc12349 (Monk) on Aug 31, 2011 at 22:42 UTC

    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: note [id://923353]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2020-11-30 02:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?