June 2008
Beginner
352 pages
11h 16m
English
Your Perl program, like any other program, runs in a certain
environment, and your program can look at the
environment to get information about its surroundings. Perl stores this
information in the %ENV hash. For instance, you’ll probably
see a PATH key in %ENV:
print "PATH is $ENV{PATH}\n";Depending on your particular setup and operating system, you’ll see something like this:
PATH is /usr/local/bin:/usr/bin:/sbin:/usr/sbin
Most of these are set for you automatically, but you can add to the environment yourself. How you do this depends on your operating system and shell:
Bourne shell$ CHARACTER=Fred; export CHARACTER $ export CHARACTER=Fredcsh% setenv CHARACTER FredDOS or Windows commandC:> set CHARACTER=Fred
Once you set these environment variables outside of your Perl program, you can access them inside your Perl program:
print "CHARACTER is $ENV{CHARACTER}\n";