Can I install a pre-configured Perl binary package

2019-04-30 01:35发布

问题:

I want to set up Perl 5.10 in my home directory in addition to the ancient Perl currently on the machine in the /usr/local. I am not a super-user on this machine.

I found the require 5.10 HPUX perl binary package and it seems to work, but for some reason it seems to assume it's running in /usr/local (as evidenced by @INC error messages). Is there some other variable in addition to PERLLIB, like PERLHOME or something I need to set so that Perl won't look for anything in the /usr/local dirs?

P.S. I seen advice online to compile and set the dir in the ./Configure step, but I been having hard time compiling things on this old box so I'd prefer to use the pre-compiled Perl since it seems mostly to work.


UPDATE -- Leon answered this, so basically it's not possible to run perl binary correctly from your home dir unless it was compiled with that in mind

回答1:

It depends on whether or not your perl binary is relocatable. It's a compile time option. What is the output of this command? Is it defined or not?

perl -V:userelocatableinc


回答2:

You're not going to like this answer.

Perl stores @INC as strings in its binary. Before there was userelocatableinc the technique to relocate Perl was to do a search and replace on the binary, as well as changing them in Config.pm. This is how ActiveState shipped a relocatable Perl.

The strings have to remain the same size as they were before, padding out any extra space with null bytes. ActiveState would get around this by configuring Perl with a prefix like "/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTMPPATHxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" or something. It also made it really unambiguous to find in the binary. You don't have such luck, so it will only work if the current paths are shorter than the paths you want to replace them with.

But that's way too complicated. Just compile Perl for yourself either using HP/UX's source or just grab the regular source from perl.org. Perl has a dedicated HP/UX developer so it should all go smoothly.



回答3:

You can point to any interpreter path you want in the first line:

!#/my/local/perl 

And if you're not looking for portability across machines, you can set @INC manually in your script. I think there's a way to get it from the env as well, which might be more portable.