Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

@INC not reflecting correctly

by dirtdog (Monk)
on Aug 26, 2021 at 21:27 UTC ( [id://11136111]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks

I have perl 5.32 installed after bringing it over from another server but put it under a different directory.

whence perl finds the perl i installed in the correct directory.

$whence perl /ajperznes/perl/bin/perl

Below is output from the perl -V command. It's showing the modules i have in PERL5LIB as being in the correct directory, but not the main 5.32 libraries. It's showing them as being in the directory from the original server that i tar'd up the package from

%ENV: PERL5LIB="/perl/myperl:/perl/myperl/OLE-Storage_Lite-0.19/lib:" @INC: /ajperznes/perl/myperl /ajperznes/perl/myperl/OLE-Storage_Lite-0.19/lib /perl/lib/5.32.0/x86_64-linux /perl/lib/5.32.0 /perl/lib/site_perl/5.32.0/x86_64-linux /perl/lib/site_perl/5.32.0 /perl/lib/5.32.0/x86_64-linux /perl/lib/5.32.0

I want the @INC to be as follows now on the new server, but for some reason it's showing it the way it is on the original server:

/ajperznes/perl/localperl /ajperznes/perl/lib/5.32.0/x86_64-linux /ajperznes/perl/lib/5.32.0 /ajperznes/perl/lib/site_perl/5.32.0/x86_64-linux /ajperznes/perl/lib/site_perl/5.32.0 /ajperznes/perl/lib/5.32.0/x86_64-linux /ajperznes/perl/lib/5.32.0

any help is greatly appreciated. Thanks in advance!

Replies are listed 'Best First'.
Re: @INC not reflecting correctly
by syphilis (Archbishop) on Aug 27, 2021 at 01:25 UTC
    I want the @INC to be as follows...

    I would firstly create the following My_INC.pm:
    package My_INC; BEGIN { @INC = qw( /ajperznes/perl/localperl /ajperznes/perl/lib/5.32.0/x86_64-linux /ajperznes/perl/lib/5.32.0 /ajperznes/perl/lib/site_perl/5.32.0/x86_64-linux /ajperznes/perl/lib/site_perl/5.32.0 /ajperznes/perl/lib/5.32.0/x86_64-linux /ajperznes/perl/lib/5.32.0 ); }; 1;
    and place it in one of the existing @INC directories directories currently listed in @INC. (Create such a directory if none currently exist.)

    Then set the PERL5OPT environment variable to -MMy_INC
    Then, every time perl is invoked, @INC is set as desired.

    On my Windows 7 machine:
    C:\>perl -le "print 'PERL5OPT: ' . $ENV{PERL5OPT}; print for @INC;" PERL5OPT: C:/perl-5.34.0/site/lib/MSWin32-x64-multi-thread C:/perl-5.34.0/site/lib C:/perl-5.34.0/lib/MSWin32-x64-multi-thread C:/perl-5.34.0/lib C:\>set PERL5OPT=-MMy_INC C:\>perl -le "print 'PERL5OPT: ' . $ENV{PERL5OPT}; print for @INC;" PERL5OPT: -MMy_INC /ajperznes/perl/localperl /ajperznes/perl/lib/5.32.0/x86_64-linux /ajperznes/perl/lib/5.32.0 /ajperznes/perl/lib/site_perl/5.32.0/x86_64-linux /ajperznes/perl/lib/site_perl/5.32.0 /ajperznes/perl/lib/5.32.0/x86_64-linux /ajperznes/perl/lib/5.32.0 C:\>
    Cheers,
    Rob
      Then, every time perl is invoked, @INC is set as desired.

      Actually, that's not quite always so. This was not what I expected:
      C:\>perl -MMath::BigInt -le "print 'PERL5OPT: ' . $ENV{PERL5OPT};print + for @INC; " PERL5OPT: -MMy_INC /ajperznes/perl/localperl /ajperznes/perl/lib/5.32.0/x86_64-linux /ajperznes/perl/lib/5.32.0 /ajperznes/perl/lib/site_perl/5.32.0/x86_64-linux /ajperznes/perl/lib/site_perl/5.32.0 /ajperznes/perl/lib/5.32.0/x86_64-linux /ajperznes/perl/lib/5.32.0
      I expected that command to fail because Math::BigInt does not exist in any of those @INC directories that are listed. (It exists only in one of my original @INC directories.)
      I expected that command to do the same as the following one-liner (in which PERL5OPT is unset):
      C:\>perl -MMy_INC -MMath::BigInt -le "print 'PERL5OPT: ' . $ENV{PERL5O +PT};print for @INC;" Can't locate Math/BigInt.pm in @INC (you may need to install the Math: +:BigInt module) (@INC contains: /ajperznes/perl/localperl /ajperznes/ +perl/lib/5.32.0/x86_64-linux /ajperznes/perl/lib/5.32.0 /ajperznes/pe +rl/lib/site_perl/5.32.0/x86_64-linux /ajperznes/perl/lib/site_perl/5. +32.0 /ajperznes/perl/lib/5.32.0/x86_64-linux /ajperznes/perl/lib/5.32 +.0). BEGIN failed--compilation aborted.
      But instead it processed the -MMath::BigInt before it processed the -MMy_INC. That is, it does the same as:
      C:\>perl -MMath::BigInt -MMy_INC -le "print 'PERL5OPT: ' . $ENV{PERL5O +PT};print for @INC;" PERL5OPT: /ajperznes/perl/localperl /ajperznes/perl/lib/5.32.0/x86_64-linux /ajperznes/perl/lib/5.32.0 /ajperznes/perl/lib/site_perl/5.32.0/x86_64-linux /ajperznes/perl/lib/site_perl/5.32.0 /ajperznes/perl/lib/5.32.0/x86_64-linux /ajperznes/perl/lib/5.32.0
      Is it possible to have perl process the contents of PERL5OPT *before* any -M... command line switches are processed ?

      UPDATE: I don't think this would be an issue for dirtdog because, IIUC, the directories in his original @INC don't exist anyway.

      Cheers,
      Rob

        I'm pretty sure this is something that the Strawberry Perl Portable editions work around. I seem to remember there is some modification of Config.pm or one of its associated files to use local values. I just can't find the mechanism at the moment.

Re: @INC not reflecting correctly
by haj (Vicar) on Aug 27, 2021 at 10:07 UTC

    So, it seems like you haven't actually installed Perl, you have unpacked a tar from another server. This explains the behavior.

    The initial list of directories in @INC is created when Perl is built, from data given to the Configure script. They end up "compiled into" the binary (a shared library for most distributions). So, unless the initial installation took care, there's no easy way to copy an installation around.

    You can fiddle with @INC at runtime as suggested by syphilis but as you see, this looks like a bit of guesswork. Is there any reason why you can't just install Perl on the target server?

    If you build your own Perl, you can use the configure option userelocatableinc (see Config) to get a Perl where @INC is created at runtime from the location of the binary. BTW: This is not how Strawberry Perl does it. Strawberry's portable editions are using Portable to do the trick, but as syphilis has noticed, you can copy the "non-portable" Strawberry editions on Windows just as well (I haven't figured out how this is done).

Re: @INC not reflecting correctly (sitecustomize.pl)
by LanX (Saint) on Aug 28, 2021 at 13:44 UTC
    Since nobody seems to have mentioned it so far...

    ... you may want to experiment with sitecustomize.pl

    from the docs:

    > The code is executed very early. For example, any changes made to @INC will show up in the output of `perl -V`

    I can't easily reproduce your problem and there is certainly a timing issue about when @INC is populated, so no guaranty whatsoever.

    HTH! :)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Re: @INC not reflecting correctly (Portable relocatable inc)
by Anonymous Monk on Aug 27, 2021 at 09:08 UTC
Re: @INC not reflecting correctly
by Anonymous Monk on Aug 27, 2021 at 16:11 UTC

    As has been noted previously, by default Perl is not relocatable. A non-relocatable Perl can be moved, but only to a new directory structure identical to the one it came from.

    However, if you are using an OS that supports symbolic links and you create symbolic links that mimic the old directory structure, you can fool Perl. This worked for me under macOS after an upgrade decided the Perl I had installed in the file system root wasn't allowed to be there, and willy-nilly moved it someplace else. I was able to get a symbolic link created to the new location, and Perl was happy.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-26 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found