Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: @INC not reflecting correctly

by syphilis (Archbishop)
on Aug 27, 2021 at 01:25 UTC ( [id://11136114]=note: print w/replies, xml ) Need Help??


in reply to @INC not reflecting correctly

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

Replies are listed 'Best First'.
Re^2: @INC not reflecting correctly
by syphilis (Archbishop) on Aug 27, 2021 at 03:44 UTC
    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.

        I'm pretty sure this is something that the Strawberry Perl Portable editions work around

        As regards @INC on Windows, there's no need to work around anything as wrt the setting of @INC.
        For example, I have a build of perl-5.30.0 in the location C:/_64/perl530_810.
        It reports @INC as being:
        C:/_64/perl530_810/site/lib C:/_64/perl530_810/lib
        I copy that perl to a new location of C:/_64/C/perl530_810.
        Without any need for me to take any additional action at all, this new perl installation correctly reports @INC as being:
        C:/_64/C/perl530_810/site/lib C:/_64/C/perl530_810/lib
        This is something that happens automatically on Windows. (I think it just looks at the location of the perl executable and derives @INC accordingly.)
        However, Linux (amazingly) apparently does not provide such a convenience.

        It's not quite so simple for portable Strawberry Perl wrt the correct treatment of %Config settings.
        I think they're probably just rewriting Config.pm and Config_heavy.pl at time of installation.
        (Again, this is a convenience that is unavailable to Linux.)

        Cheers,
        Rob

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-24 05:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found