How do I set an environment variable in Perl?
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.
$ENV{'HOME'} = '/path/to/new/home';
Also see perlrun