Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

setting ENV variables

by vikee (Sexton)
on Jun 22, 2004 at 14:33 UTC ( #368735=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://368735]
Approved by integral
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2022-06-30 20:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (98 votes). Check out past polls.

    Notices?