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

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;

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/

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