sagibeli has asked for the wisdom of the Perl Monks concerning the following question:

Hello, There is a unix environment variable called ARCH which i want to remove by a perl script (like using unsetenv commnad in unix). I was tring using: system("unsetenv ARCH") but the variable wasn't remove. I would like the variable to be removed from the shell which the script is loaded from. Thanks, Sagi

Replies are listed 'Best First'.
Re: unsetenv in perl
by Corion (Patriarch) on Oct 26, 2008 at 09:41 UTC

    This is not possible under Unix unless you get some cooperation from your invoking shell. The calling shell is a separate program which you cannot modify. The common approach is to output a shell script from your program and evaluate that shell script in the calling shell:

    $ eval $(myscript.pl)
Re: unsetenv in perl
by moritz (Cardinal) on Oct 26, 2008 at 09:52 UTC
    Additionally to what Corion said, if you want to only remove the environment variable for the script itself, and for sub processes that your script launches, you can use use delete $ENV{ARCH}.

    See also: %ENV.