Alex Rivera | Logout

How do I set an environment variable in Perl?

Asked 2009-11-17T10:04:17.180
21

How do I set an environment variable in Perl?

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

Edit
Report

1 Answer

42

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.

As perldoc -v %ENV says:

%ENV The hash %ENV contains your current environment. Setting a value in "ENV" changes the environment for any child processes you subsequently "fork()" off.

answered 2009-11-17T10:08:32.663

Your Answer