http://www.perlmonks.org?node_id=1026852


in reply to Get home dir from shell

If $ENV{HOME} is not set, it won't be set in the shell either.

Most likely, your login environment is not set up because your script is running as the CGI user, or if it is running as your user, the login / .profile scripts have not been run.

See Get default login environment and the replies for how to set up the environment from a script.