O'Reilly logo

Programming Perl, 3rd Edition by Jon Orwant, Tom Christiansen, Larry Wall

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

HOME

Used if chdir is called without an argument.

LC_ALL, LC_CTYPE, LC_COLLATE, LC_NUMERIC, PERL_BADLANG

Environment variables that control how Perl handles data specific to particular natural languages. See the online docs for perllocale.

LOGDIR

Used if chdir has no argument, but HOME is not set.

PATH

Used in executing subprocesses, and for finding the program if the -S switch is used.

PERL5LIB

A colon-separated list of directories in which to look for Perl library files before looking in the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required