Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Compiling Perl with correct values in @INC

by higle (Chaplain)
on Aug 15, 2002 at 18:10 UTC ( #190478=perlquestion: print w/ replies, xml ) Need Help??
higle has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks--

I'm running up against a sticky issue. One of my company's machines is running Perl with an incorrectly compiled @INC array, so any scripts calling modules won't run properly.

I've been using a temporary fixit by exporting the PERL5LIB environment variable in my shell profile. Of course, this works fine for command line scripts, but CGIs don't work.

I don't want to have to add the correct values to @INC every time that I write a script, so the obvious solution would be to recompile Perl with the correct @INC values. This leads to the problem: I've never compiled the Perl executable before, and I don't know how @INC gets assigned during the compile.

The Unix admins are expecting me to provide some kind of instructions on this, and I've searched Perl's documentation and all over the Web with no real results. I'm hoping that this means it is a moot point, and somehow the @INC thing takes care of itself when compiled, but I wouldn't know, and I can't find any helpful info on the subject.

Could someone with some experience on this alleviate my ignorance? :)

Thanks, as always,

  higle

Comment on Compiling Perl with correct values in @INC
Re: Compiling Perl with correct values in @INC
by Necos (Friar) on Aug 15, 2002 at 18:42 UTC
    Looking at my Config.pm file, there seems to be some options for path inclusion of libraries.

    Here are some of the more interesting lines from my Win32 machine:

    archlib='C:\Perl\lib' privlibexp='C:\Perl\lib' glibpth='/usr/shlib /lib/pa1.1 /usr/lib/large /lib /usr/lib /usr/lib/ +386 /lib/386 /lib/large /usr/lib/small /lib/small /usr/ccs/lib /usr/u +cblib /usr/shlib ' installsitearch='C:\Perl\site\lib' installsitelib='C:\Perl\site\lib' locincpth='/usr/local/include /opt/local/include /usr/gnu/include /opt +/gnu/include /usr/GNU/include /opt/GNU/include' loclibpth='/usr/local/lib /opt/local/lib /usr/gnu/lib /opt/gnu/lib /us +r/GNU/lib /opt/GNU/lib' sitearch='C:\Perl\site\lib' sitearchexp='C:\Perl\site\lib' sitelib='C:\Perl\site\lib' sitelibexp='C:\Perl\site\lib' xlibpth='/usr/lib/386 /lib/386'
    You might want to check your Config.pm and see if all the lib paths are correct. This might help you to correct the @INC array (it should, but I may be wrong). Hope this helps some.

    Update: I should note that even though I looked at a Win32 Config.pm, some of the ideas should apply. I forget whether or not scripts/programs/etc. read from Config.pm unless explicitly stated (i.e., use Config;). If I am wrong, I'd like some correction on the issue.

    Theodore Charles III
    Network Administrator
    Los Angeles Senior High
    4650 W. Olympic Blvd.
    Los Angeles, CA 90019
    323-937-3210 ext. 224
    email->secon_kun@hotmail.com
    perl -e "map{print++$_}split//,Mdbnr;"

      Editing Config.pm won't help anything. It's written when Perl is compiled from the config.sh file built by Configure.sh. The basic @INC paths are compiled into the Perl binary itself. Think about it this way -- if Perl can be installed just about anywhere (and it can be), how would it know where to find Config to find out where the modules are installed?

      Of course, when your @INC is incorrect, perl can't find Config.pm....
      $ perl -wle 'BEGIN {@INC = ()} use Config' Can't locate Config.pm in @INC (@INC contains:) at -e line 1. BEGIN failed--compilation aborted at -e line 1.

      Abigail

Re: Compiling Perl with correct values in @INC
by Zaxo (Archbishop) on Aug 15, 2002 at 18:49 UTC

    By default, the perl build configuration does an extended question-and-answer session during the configuration. Default answers are provided and are sane for most questions. If you give an incorrect answer, it's best to start over. You get a chance to edit the configuration before it's written into the Makefile.

    Since some default answers may be drawn from the current perl installation, pay close attention to the LIBDIR and 'additional @ISA' questions. The -d option to configure automatically picks most of the defaults, so don't try that with a broken current perl.

    It would be advisable to set PERL5LIBS before building.

    After Compline,
    Zaxo

Re: Compiling Perl with correct values in @INC
by higle (Chaplain) on Aug 15, 2002 at 19:29 UTC
    Thanks guys! The help is very much appreciated!

    I've never dug into this part of the Perl beast until now, and I've found it rather hard to locate documentation outlining the building of the Perl executable. Is there a handy source of documents on this subject (read: a URL that I can give to the Unix dudes), or is this coming purely from experience and the READMEs?

    Thanks some more,

      higle

    Update: Whew, got it all sorted out. Thanks to Zaxo, I was able to confidently reassure the Unix guys (and their managers, so on and so forth) that the change would be a painless one. Perl was rebuilt and configured with the appropriate lib paths. Thanks again to everyone and their contributions!
Re: Compiling Perl with correct values in @INC
by Courage (Parson) on Aug 15, 2002 at 20:14 UTC
    1. perl built on different OSes has different logic for @INC population.
    2. Your script will work just fine if you'll place at the very start of it:
      BEGIN { @INC = ('/dir1','/your/special/dir/here'); } # rest of your code goes here
      I use that approach sometimes in my scripts.
    3. recompiling perl is much easier that it initially seemes to. And lot of platform-specific READMEs help a lot.
    addition: BTW what is your OS?

    Courage, the Cowardly Dog
    things, I do for love to perl...

      The machine in question is running HP-UX, and I found one (1) document specific to building perl on that OS :c\

      The problem was, Courage, without rebuilding the executable with the correct @INC, I would have to unshift(@INC, qw{dir dir dir...}); all the scripts that I wrote on that machine, as well as look forward to explaining this whole thing to the other programmers who use that box. That would truly have been a bummer of cosmic proportions.

        higle
        Things are entirely different if you're building perl for many users on that machine.

        I just looked at perl-5.8.0 source distribution, and found README.HPUX file there - it should help you in build process...

        Courage, the Cowardly Dog

      This also works great if your hosting company doesn't want to install a particular module.
Re: Compiling Perl with correct values in @INC
by wrffr (Novice) on Aug 16, 2002 at 03:35 UTC
    If you can't rebuild the perl executable or you want to keep certain perl modules in a different directory for other reasons, just stick--

      use lib "/path/to/perl/modules";

    ...at the beginning of your script.

      Which actually works quite well using mod_perl:
      <Perl> use lib "/my/modules/path"; </Perl>
      As a note, you have to build that thing properly when compiling it in:
      % perl Makefile.PL EVERYTHING=1
      this will work but only in cases when perl will find "lib.pm" which, in turn, requires "Config.pm" and "Exporter.pm".
      That said, @INC must be sane in this case.

      I agree that @INC should *always* be sane, but what you will do if it is not? :)

      Warmest wishes,
      Courage, the Cowardly Dog

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://190478]
Approved by djantzen
Front-paged by defyance
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (16)
As of 2014-08-22 17:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (161 votes), past polls