http://qs1969.pair.com?node_id=368735

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

Hello,
how can I add my own variable to the %ENV and set it?

from the command promt: set something=true

Replies are listed 'Best First'.
Re: setting ENV variables
by pbeckingham (Parson) on Jun 22, 2004 at 14:35 UTC

    Try this:

    $ENV{'myVariable'} = 'myValue';
    But it won't persist outside your program.

      Erm, no. It will affect the process you set it in and any of its children; it won't affect the parent process (which is what you may be thinking of).

        What are you saying 'Erm, no' to?

        The %ENV hash is modifiable, it won't be reflected outside the program, and is in no way permanent.

      I need somthing that works both on unix and win from a perl. I think that it needs not to be persistent, just for the childs.
      
      thanks
      
Re: setting ENV variables
by bibo (Pilgrim) on Jun 22, 2004 at 14:38 UTC
    the shell startup files are one place where env vars are set.

    if you mean setting them inside a perl script, hmmmm I would search the perl docs for "environment variables"

    yes, there is a module called "Env" which should help you read and set variables...

    perldoc Env should help with the details

      Yep, a good place to look is perldoc -q environment

      --
      bm
Re: setting ENV variables
by bassplayer (Monsignor) on Jun 22, 2004 at 14:50 UTC
    Not sure if you mean from a perl script or not. From system command line (in Linux), this works:

    export PERLMONKS=EDUCATIONAL.

    I believe that settings made using this format (system call from script) will persist after your script has finished, but not to other web processes, for example.

    Update: Not it won't. :-( That'll teach me not to test first. :-) The above does work from command line though.

    bassplayer