perlenvironment-variables

How do I set an environment variable in Perl?


How do I set an environment variable in Perl?

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


Solution

  • 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.