Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Basic - Perl5lib

by Anonymous Monk
on Oct 27, 2010 at 22:56 UTC ( #867860=perlquestion: print w/replies, xml ) Need Help??

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

Dear Monks

I'm trying to understand the PERL5LIB environment variable and how it relates to multiple versions of Perl on the same machine

I have tried echoing the PERL5LIB variable and I get a blank line. Does that mean its empty? In other words, it doesn't have a default value and you have to set it manually? If you have multiple versions of Perl do they share the same PERL5LIB?

Thank-you in advance

Replies are listed 'Best First'.
Re: Basic - Perl5lib
by Khen1950fx (Canon) on Oct 27, 2010 at 23:58 UTC
    PERL5LIB looks for modules in a private directory, for example, a development directory. If you want to use the modules in the development directory, then you can tell Perl to add the development directory to the front of @INC like this:

     export PERL5LIB=/home/uid/lib/perl5

      ..and typically you'd set that environment variable so that all your processes/scripts had access to that additional module directory. otherwise just add an additional module directory directly in a perl script by pushing it onto @INC in a begin section. example for modules in specified directory and/or current directory
      BEGIN { $my_module_dir = '~/myperl_modules/`; push(@INC, ('.',"$my_module_dir")); } use mymodule; ...
      oracle installs (and embedded) perl and it's own set of modules, and sets perl5lib. so not a good idea to modify perl5lib on oracle systems unless you really know what you're doing.
      the hardest line to type correctly is: stty erase ^H
        The more common way to add to @INC from within your program is with use lib. The following is equivalent to (more concise than) the code above:
        use lib qw( . ~/myperl_modules/ ); use mymodule;
        ...except that use lib puts the extra dirs at the start of @INC (giving them precedence over system modules, which is normally what you want) while your use of push puts them at the end (giving system modules precedence, which is normally not what you want).

        Thanks for your replies. How can I set the PERL5LIB environment variable if I don't have one?

        If I do manage to find my missing PERL5LIB, is it shared by all my Perl installations?

Re: Basic - Perl5lib
by toolic (Bishop) on Oct 27, 2010 at 23:39 UTC
    perl does not require that the PERL5LIB environment variable be set. Typically, the variable will not be set to any value.

    One common usage scenario is to set the variable to a directory which contains Perl modules that you have developed.

Re: Basic - Perl5lib
by ikegami (Patriarch) on Oct 27, 2010 at 23:00 UTC

    If you have multiple versions of Perl do they share the same PERL5LIB?

    Environment variables are inherited from the parent process.

    In other words, it doesn't have a default value and you have to set it manually?

    It depends on what you mean by default value. You could set it in your login script, for example.

      I don't have a PERL5LIB environment variable?? When i run env command it isn't in the list and I get nothing from this Perl program
      #!/usr/bin/perl print "PERL5LIB: ", $ENV{PERL5LIB}, "\n"; print "done\n";

        So you don't. Is that a question?

        Perhaps you are missing the point of the variable: To specify additional locations to search for modules.

Re: Basic - Perl5lib
by Anonymous Monk on Oct 28, 2010 at 07:17 UTC
    You also might be interested in seeing how perlbrew manages switching between different versions.

      I am worried about how the PERL5 LIB env variable affects different perl installations. I am presuming they share the same one. However I want to be sure that if I set the PERL5LIB for my local installation that it won't mess up the system installation. I want to include certain module versions for use by my local installation and I know if i set PERL5LIB it is prepended to the @INC array. Presumably this will affect my system installation too. I don't know if I can avoid this or whether it means I shouldn't use the PERL5LIB variable and I should use 'use lib' to modify the INC array.

        PERL5LIB affects perl processes (every perl process will use PERL5LIB), it doesn't affect installations

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2022-12-05 11:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?