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);

In reply to Re: Set LD_LIBRARY_PATH and restart program by runrig
in thread Set LD_LIBRARY_PATH and restart program by runrig

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.