Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Push local lib paths to @INC array

by hacksics (Initiate)
on Dec 25, 2008 at 17:23 UTC ( [id://732601]=perlquestion: print w/replies, xml ) Need Help??

hacksics has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone,
Is there any way to push a variable to @INC array in perl. I've noted if the full path is given then it accepts but a variable is given then it ignores,
Ex:
push @INC, "/home/user_x/custom_libs"; # working my $LIB_PATH = "/home/user_x/custom_libs"; push @INC, $LIB_PATH; # not working
Thanks,

Replies are listed 'Best First'.
Re: Push local lib paths to @INC array
by chromatic (Archbishop) on Dec 25, 2008 at 17:32 UTC

    How do you know it's "not working"? Print the contents of @INC before and after the push, and you'll see that it is (or you have a broken Perl installation).

    Note, however, that if you want to modify @INC before loading a module with use, you need to put the modifications in a BEGIN block -- and that includes setting the value of the variable.

      Ya, Thanks,
      It is working fine inside a BEGIN block (both variable assignment and push statement)
Re: Push local lib paths to @INC array
by jwkrahn (Abbot) on Dec 25, 2008 at 17:32 UTC

    Use the lib pragma to add paths to @INC.

Re: Push local lib paths to @INC array
by vlsimpson (Beadle) on Dec 25, 2008 at 18:04 UTC

    I use 'use lib' (sorry) in combination with 'FindBin' with a Perl/Tk app I'm working on.,

    use FindBin; use lib $FindBin::Bin . '/lib';

    FindBin documentation

Re: Push local lib paths to @INC array
by gube (Parson) on Dec 26, 2008 at 21:22 UTC
    If your application has many modules and many scripts lets say 100, instead adding these lines in each and every file and model class, you can export simply in command prompt while running the script. In linux terminal export PERL5LIB=/home/gubendran/dashboard/trunk/lib/ This will work till you close the terminal. This avoid adding code in each and every script and you can change the library path anytime.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-26 02:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found