views:

137

answers:

3

How do I set an environment variable in Perl?

I want to set $HOME to a different directory than the default.

A: 

How do I set environment variables in Perl programs?

Priyank Bolia
I have searched for the answer in SO first but couldn't find it, and then googled it.I've asked the question here because I SO to be my #1 stop for programming questions.
not sure what you search, the above link is the first result from the query at google: http://www.google.com/search?q=set+environment+variables+in+Perl
Priyank Bolia
Plus there are many examples at SO also: http://stackoverflow.com/questions/512613/how-can-i-set-the-windows-path-variable-from-perl
Priyank Bolia
If you think this is a dupe, simply add a comment to the question or flag it for moderator attention. No reason to post snotty answers.
innaM
+12  A: 

You can do it like this:

$ENV{HOME} = 'something different';

But please note that this will only have an effect within the rest of your script. When your script exits, the calling shell will not see any changes.

innaM
+4  A: 
$ENV{'HOME'} = '/path/to/new/home';

Also see perlrun

David