Environment Variables

In addition to the various switches that explicitly modify Perl's behavior, you can set various environment variables to influence various underlying behaviors. How you set up these environment variables is system dependent, but one trick you should know if you use sh, ksh, or bash is that you can temporarily set an environment variable for a single command, as if it were a funny kind of switch. It has to be set in front of the command:

$ PATH="/bin:/usr/bin" perl myproggie 


You can do something similar with a subshell in csh and tcsh:

% (setenv PATH "/bin:/usr/bin"; perl myproggie) 


Otherwise, you'd typically set environment variables in some file with a name resembling chsrc or profile in your home directory. Under csh and tcsh you'd say:

% setenv PATH '/bin:/usr/bin' 


And under sh, ksh, and bash you'd say:

$ PATH="/bin:/usr/bin"; export PATH 


Other systems will have other ways of setting these on a semi-permanent basis. Here are the environment variables Perl pays attention to:

Apart from these, Perl itself uses no other environment variables, except to make them available to the program being executed and to any child processes that program launches. Some modules, standard or otherwise, may care about other environment variables. For example, the use re pragma uses PERL_RE_TC and PERL_RE_COLORS, the Cwd module uses PWD, and the CGI module uses the many environment variables set by your HTTP daemon (that is, your web server) to pass information to the CGI script.

Programs running setuid would do well to execute the following lines before doing anything else, just to keep people honest:

$ENV{PATH} = '/bin:/usr/bin'; # or whatever you need $ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};


See "Security" for details.