[Israel.pm] Removing PERLLIB additions to @INC
David Baird
david.baird at homemail.com
Tue Jan 13 03:48:44 PST 2004
Not to beat a dead horse... But,
I was updating some old code, and again came across the need to remove
and additions made to @INC by PERLLIB. Recall a suggestion by Gabor:
> BEGIN {
> if (defined $ENV{PERLLIB}) {
> foreach my $path (split /;/, $ENV{PERLLIB}) {
> @INC = grep {lc $path ne lc $_} @INC;
> }
> }
> }
Good enough. But I also thought of another solution, which works on any
OS platform. My solution simply reverses INC, which gives higher
priority to the built-in module library paths. In a situation where I
don't want additions made by the end user through PERLLIB, this seems to
be the most straight forward approach.
BEGIN { @INC = reverse @INC; }
use Socket;
You may say, well, Socket is standard and in any case, why would someone
who added PERLLIB to their environment hurt anything? I am maintaining a
script which must work in any situation and which is run by a
specialized version of Perl. There are occasions where a module like
Socket is placed in a set of Perl modules, which are not compatible with
my specialized version of Perl. I need to make sure that my script only
loads modules from my specialized Perl installation.
Thoughts?
-David
More information about the Perl
mailing list