Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

manipulating environment variables

by opensourcer (Monk)
on Apr 22, 2010 at 10:58 UTC ( #836222=perlquestion: print w/replies, xml ) Need Help??
opensourcer has asked for the wisdom of the Perl Monks concerning the following question:

How do I manipulate ENV variable, example: ------- %MCONF = ( NAME => 'SOURCER', JOB => 'BATCH', );
and I want to use MCONF hash keys NAME and JOB in another script or module as $ENV{NAME}.

Replies are listed 'Best First'.
Re: manipulating environment variables
by almut (Canon) on Apr 22, 2010 at 11:28 UTC
    for my $name (keys %MCONF) { $ENV{$name} = $MCONF{$name}; }

    (but note that this only has an effect for the current process and its subprocesses)

Re: manipulating environment variables
by zwon (Abbot) on Apr 22, 2010 at 11:35 UTC

    You can assign values to %ENV the same way you assigning values to usual hash. If other script is child of current process created after you assigned value to $ENV{NAME}, the value will be available in this script. If other script is not child of the current process, than you should use some other way to pass value to it, there's no practical way one process could change environment of the other process.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://836222]
Approved by ahmad
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2017-12-13 20:42 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (378 votes). Check out past polls.