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

Hi all, I have 5.10.0 installed in my system(SUSE Linux).
I have a product installed in /opt which has its bundled perl of version 5.8.8.

Consider a script 8.pl of this product which runs using 5.8.8 perl(using shebang line).Also consider a script 10.pl which uses(using shebang line). 10.pl needs a module M which is available in 5.10's module location as well as in 5.8.8's module location under /opt.

Now 8.pl needs to invoke 10.pl as a system command. Now, the problem is- M being loaded is from 5.8.8 module stack and not the system stack of 5.10. The two versions of M are incompatible.

The problem is that @INC array is set as per 5.8.8's module locations when 8.pl is run. Here is the @INC array when 8.pl starts:

/opt/zmanda/amanda/perl/lib/5.8.8/i686-linux-thread-multi /opt/zmanda/amanda/perl/lib/5.8.8 /opt/zmanda/amanda/perl/lib/site_perl/5.8.8/i686-linux-thread-multi /opt/zmanda/amanda/perl/lib/site_perl/5.8.8 /opt/zmanda/amanda/perl/lib/5.8.8/i686-linux-thread-multi /opt/zmanda/amanda/perl/lib/5.8.8 /opt/zmanda/amanda/perl/lib/site_perl/5.8.8/i686-linux-thread-multi /opt/zmanda/amanda/perl/lib/site_perl/5.8.8 /bitrock/zmanda/output/perl/lib/5.8.8/i686-linux-thread-multi /bitrock/zmanda/output/perl/lib/5.8.8 /bitrock/zmanda/output/perl/lib/site_perl/5.8.8/i686-linux-thread-mult +i /bitrock/zmanda/output/perl/lib/site_perl/5.8.8 /bitrock/zmanda/output/perl/lib/site_perl
Now when 10.pl runs from 8.pl, the @INC array has this:
/opt/zmanda/amanda/perl/lib/5.8.8 /opt/zmanda/amanda/perl/lib/site_perl/5.8.8 /usr/lib/perl5/5.10.0/x86_64-linux-thread-multi /usr/lib/perl5/5.10.0 /usr/lib/perl5/site_perl/5.10.0/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.10.0 /usr/lib/perl5/vendor_perl/5.10.0/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.10.0 /usr/lib/perl5/vendor_perl
Note the first 2 paths here. There belong to 5.8.8 perl.Rest paths are correctly perl 5.10's.How to do this?
I tried wiping out @INC array before calling 10.pl by
@INC = ();
before running 10.pl. But it doesn't help.

Any help much appreciated..
Thanks,

Replies are listed 'Best First'.
Re: @INC array and two perl versions
by bart (Canon) on Feb 04, 2010 at 13:27 UTC

    Why are /opt/zmanda/amanda/perl/lib/5.8.8 and /opt/zmanda/amanda/perl/lib/site_perl/5.8.8 even in @INC? You must have added them (manually) in some way. Note that they appear twice in the @INC for perl 5.8.8.

    I am guessing somebody added them to the environment variable PERL5LIB, or something equivalent (for example: direct use of use lib). Don't do that: when lib adds a directory to @INC, it'll also add version dependent subdirectories. That goes for the contents of PERL5LIB, too.

    That's most likely why they appear twice for 5.8.8.

      Awesome! Works now!
      However, PERL5LIB was not set in my environment.But when I run 8.pl(which has #!/opt/zmanda.... /perl shebang) PERL5LIB starts having those two paths. How did that happen? The 5.8.8 perl was compiled that way? Update Opps I forgot to mention what fixed it. Just before calling 10.pl, I unset PERL5LIB env variable.
Re: @INC array and two perl versions
by almut (Canon) on Feb 04, 2010 at 13:27 UTC

    If I'm understanding you correctly, you want 10.pl to look in additional lib directories, which are not set by default when 10.pl is being run via system from within 8.pl (?)

    If so, you could set PERL5LIB prior to calling 10.pl, or call the perl interpreter explicitly, passing it the additional lib directories via one or more -I options (see perlrun).

    Update: actually, reading the other replies, it appears you don't want the 5.8 directories on the lib list for 10.pl ... in which case try unsetting PERL5LIBPERL5LIB might be one reason for them being there.

Re: @INC array and two perl versions
by moritz (Cardinal) on Feb 04, 2010 at 13:28 UTC

    How do you run the second script? If you go through system or exec, no variables that you change in the first script should have any effect on the second - except %ENV.

    Also if you go through system, the @INC should be independent from the caller.

    So please check if you have any perl-related environment variables set, and unset them if necessary. See perlrun for a list of variables that influence perl.

    Perl 6 - links to (nearly) everything that is Perl 6.
Re: @INC array and two perl versions
by zentara (Cardinal) on Feb 04, 2010 at 13:25 UTC
      Actually, I need a generic solution. A system may have many conflicting modules installed for different perl versions.
      Basically 10.pl can be run from shell without problem. I want it to be invocable from 8.pl just like that.
Re: @INC array and two perl versions
by ikegami (Patriarch) on Feb 04, 2010 at 15:36 UTC

    Now 8.pl needs to invoke 10.pl as a system command. Now, the problem is- M being loaded is from 5.8.8 module stack and not the system stack of 5.10.

    Sorry, but that's not possible. A child process cannot see a variable in its parent process. There's no way a Perl 5.10 process sees the @INC of a Perl 5.8 process.

    The problem is that you somehow told the Perl 5.10 process to use the Perl 5.8 lib dirs. Possible means of doing so:

    • -I command line option
    • -Mlib command line option
    • PERL5LIB env var
    • PERLLIB env var
Re: @INC array and two perl versions
by nikunjv (Initiate) on Feb 05, 2010 at 09:15 UTC
    Thanks to all. Ikegami- yes you are right. It was a problem of PERL5LIB getting set automatically with two paths of 5.8.8 perl when 8.pl was getting executed. I am not sure how PERL5LIB got set though..