Environment Variables

When you run a CGI on the server, it has access to various information that the server and Perl interpreter make available to it. This makes up a part of the environment in which the CGI runs. It contains all sorts of information, such as the name of the web server, the name and path of the CGI file, the users browser type and more. All of this information is contained in a special associative array called "%ENV", which you can access at any place in your CGI.

While you can access this data at any time, you should be aware of a few restrictions.

You need to access the environment variables in the same manner you access data in other associative arrays:

$data = $ENV{'VARIABLE_NAME'};

Simply replace VARIABLE_NAME with the environment variable that you want to use. Then you can print it out in your output to the browser or a file or do whatever else you want with it.

Here is the list of all the environment variables and what they contain. (NOTE: Some won't contain any info):