#!/usr/bin/perl ## ## printenv -- demo CGI program which just prints its environment ## # Start the page by outputing the Content-type header print "Content-type: text/html\n\n"; print "

This is a list of the environment variables

\n"; print "
\n";

foreach $var (sort(keys(%ENV))) {
    $val = $ENV{$var};
    $val =~ s|\n|\\n|g;
    $val =~ s|"|\\"|g;
    print "${var}=\"${val}\"\n";
}

print "
\n"; if ($ENV{"REQUEST_METHOD"} eq "POST") { print "

This is a POST

\n"; print "The Query String is empty. The arguments come in the\n"; print "body of the HTTP request message. Here it is.\n"; print "
";
	while()
	{
		print $_;
		$argline = $argline . $_;
	}
	print "
"; ParseArgs($argline); } elsif ($ENV{"REQUEST_METHOD"} eq "GET") { print "

This is a GET

\n"; print "The Query String is in the environment\n"; ParseArgs($ENV{"QUERY_STRING"}); } else { print "

Unknown method

\n"; } sub ParseArgs { my $argline = shift(@_); my @args = split /&/, $argline; print "

Here are the arguments parsed

"; print "
\n";
	for($i = 0; $i <= $#args; $i++)
	{
		($name,$value) = split /=/, $args[$i];
		print "Arg $i name is: [$name]\n";
		print "Arg $i value is: [$value]\n";
	}
	print "
\n"; }