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

That can be simplified to:
BEGIN { if (exists $ENV{LIBPATH}) { delete $ENV{LIBPATH}; exec $^X, __FILE__, @ARGV; } }

Replies are listed 'Best First'.
Re^7: replicating the command 'unset LIBPATH' in perl
by viffer (Beadle) on May 19, 2010 at 02:07 UTC
    Thanks gents - I now feel like the beginner I am!

    But....what is __FILE__?

      Its not a secret :) __FILE__ site:perldoc.perl.org The special literals __FILE__, __LINE__, and __PACKAGE__ represent the current filename, line number, and package name at that point in your program.
      $ perl -e"die __FILE__" -e at -e line 1. $ echo die __FILE__ > thefileis $ perl -e"die __FILE__" -e at -e line 1. $ echo die __FILE__ > thefileis $ perl thefileis thefileis at thefileis line 1. $ perl D:\thefileis D:\thefileis at D:\thefileis line 1. $
        OK - so __FILE__ is the name of my script, but I will admit to not understanding what you're trying to do with it.

        When I run your version of the BEGIN code, I get

        Use of uninitialized value in string eq at /apps/bin/blah/reconcile_wi +thdotsh.pl line 68. main::BEGIN() called at /apps/bin/blah/reconcile_withdotsh.pl +line 73 eval {...} called at /apps/bin/blah/reconcile_withdotsh.pl lin +e 73
        where lines 68 and 73 are:
        67 BEGIN { 68 unless( $ENV{ +__FILE__ } eq __FILE__ ){ 69 delete $ENV{LIBPATH}; 70 $ENV{ +__FILE__ } = __FILE__; 71 exec $^X, __FILE__, @ARGV; # relaunch without LIBPATH 72 } 73}
        It isn't __FILE__ that is the uninitialized value (as I put a print command in), so presumably its the "$ENV{ +__FILE__ }" but I can't manage to print that to check - and being in a BEGIN statement I can't step through it in debug.

        Also, in both versions the script just ends (as opposed to terminating with an error).

        Maybe I should be a heretic and go back to using COBOL on a mainframe! Do any still exist?

        Cheers

        Kev