in reply to Re^2: replicating the command 'unset LIBPATH' in perl
in thread replicating the command 'unset LIBPATH' in perl

I had tried the delete $ENV{LIBPATH} and it's right near the top of script.

You missed the part about using BEGIN. The idea is to execute it before any use statements are executed, and you'll need BEGIN for that.

BEGIN { delete $ENV{LIBPATH} }

Replies are listed 'Best First'.
Re^4: replicating the command 'unset LIBPATH' in perl
by viffer (Beadle) on May 18, 2010 at 06:35 UTC
    Again thanks. I have put it in a BEGIN statement - and again, whilst it does appear to unset the libpath, it doesn't enable me to connect to the database. The *only* command that seems to work is running unset LIBPATH prior to running the script.

    It would seem the super user account has the db2profile as default environment.

    It runs both applications which require db2inst1 profile (db2 v8) and db2inst2 profile (db2 v9).

    The thought is now to consider setting db2profile env before app start and not having db2profile in the super user profile - although the person charged with doing that seems overly reticent (without giving his reasons) to do it.

    Cheers for your help

      This should work
      #!/usr/bin/perl -- BEGIN { unless( $ENV{ +__FILE__ } eq __FILE__ ){ delete $ENV{LIBPATH}; $ENV{ +__FILE__ } = __FILE__; exec $^X, __FILE__, @ARGV; # relaunch without LIBPATH } } ...
        That can be simplified to:
        BEGIN { if (exists $ENV{LIBPATH}) { delete $ENV{LIBPATH}; exec $^X, __FILE__, @ARGV; } }