in reply to Problems with Setenv within Perl

Your code

`setenv PEOPLE 5033`
launches a shell, sets the environment variable in that shell, then the shell quits, and the var is gone. To preserve the value, I believe your only option is to set the var, then exec, but that's hardly a solution for what (little) you describe.

Replies are listed 'Best First'.
Re^2: Problems with Setenv within Perl
by sgifford (Prior) on Jul 21, 2004 at 19:40 UTC
    It's not necessary to use the shell to set a variable. Just:
    $ENV{PEOPLE}=5033;
    should suffice.
      Yes, setting the value of %ENV will automatically set the enverioment variable outside the process, and after the process die it will restore the previous values.

      Note that some keys can't be set, for example, on Win2K we can't set wrong keys like PATH, PATHEXT e HOMEPATH. But if you are just setting a new key it will work just fine.

      Graciliano M. P.
      "Creativity is the expression of the liberty".

        That seems like a confusing way to look at it. At least under Unix, setting %ENV will set the environment variable in the running Perl process. That environment is inherited by all processes which are started from that process. The environment is never "changed back"; when the process exits, its environment goes away with all of its other data.