Here is a more flexible version that can remove paths or add paths to the beginning or end of the path (note: if you add to the beginning, they will be added in reverse order): sub import {
return if $ENV{FIXINIT_PM};
my $class = shift;
my @chk = $^C ? '-c' : ();
$ENV{FIXINIT_PM} = 1;
my @path = split /:/, $ENV{LD_LIBRARY_PATH};
while ( my $dir = shift @_ ) {
last if $dir eq "--";
if ( $dir =~ s/^-// ) {
if ($dir eq 'all') {
@path = ();
next;
}
@path = grep $_ ne $dir, @path;
next;
}
if ( $dir =~ s/^\+// ) {
unshift @path, $dir;
next;
}
push @path, $dir;
}
$ENV{LD_LIBRARY_PATH} = join ":", @path;
my %env = @_;
$ENV{keys %env} = values %env;
exec $^X => @chk, $0, @ARGV;
die "Could not exec $^X $0: $!";
}
New pod: =head1 SYNOPSIS
# Use before all other use statements
# Unset LD_LIBRARY_PATH
use FixInit;
# Add paths to end of LD_LIBRARY_PATH and set some variables
# "--" divides paths and env variables
use FixInit qw(libpath1 libpath2 -- env1 value1 env2 value2);
# Add paths to beginning of LD_LIBRARY_PATH
# (Will get added in reverse order)
use FixInit qw(+libpath2 +libpath1);
# Remove paths from LD_LIBRARY_PATH
use FixInit qw(-libpath1 -libpath2);
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|