Examples in Perl

Environment Variables

The environment variables provided can be quite useful. Here is a script to display the ones available :

#!/usr/bin/perl

print "Content-type: text/html", "\n\n";
print "";

foreach $Env_key (keys %ENV) {
    print "ENV{$Env_key} = $ENV{$Env_key}
"; }

Here's some sample output from the script (only a few lines):

ENV{HTTP_USER_AGENT} = Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)
ENV{SERVER_PORT} = 80
ENV{REQUEST_METHOD} = GET
ENV{REMOTE_USER} = user
ENV{SERVER_PROTOCOL} = HTTP/1.0
ENV{GATEWAY_INTERFACE} = CGI/1.1
ENV{HTTP_HOST} = www.motreja.com

The output shows that the browser used was IE 5.0 on Windows 98.
The connection was made to port 80, the default HTTP port.
Request method was GET.
The username entered was user. This would typically show up if you use .htaccess files for password protection.
The HTTP protocol used is HTTP/1.0
The CGI version used is CGI/1.1
The host is www.motreja.com


Back to Table of Contents