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

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 } } ...

Replies are listed 'Best First'.
Re^6: replicating the command 'unset LIBPATH' in perl
by JavaFan (Canon) on May 18, 2010 at 07:35 UTC
    That can be simplified to:
    BEGIN { if (exists $ENV{LIBPATH}) { delete $ENV{LIBPATH}; exec $^X, __FILE__, @ARGV; } }
      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. $