Using Variables in CGI

by on October 10th, 2007

This is an example of simple CGI variable usage in scripts. The ordinary way and the extraordinary and right way.

#!/usr/bin/perl -w
use strict;
use CGI;
my $q = CGI::Vars();
print "Content-Type: text/plain\n\n";
print "\n";
print "Versions:\n=================\n";
print "perl: $]\n";
print "CGI: $CGI::VERSION\n";
print "\n";
print "CGI Values:\n=================\n";
for my $k (sort keys %$q) {
print "$k [$q->{$k}]\n";
print "\n";
print "Environment Variables:\n=================\n";
for my $k (sort keys %ENV) {
print "$k [$ENV{$k}]\n";
print "\n";
Second Example
#!/usr/bin/perl -wt
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
my $email = "someone\";
my $url = "";
print header;
print start_html("Scalars");
print <Hello

My e-mail address is $email, and my web url is $url.

EndHTML print end_html;
Download Script

Download CGI variables Script