Using Variables in CGI

by Hiroshi on 10-10-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\@server.com";
my $url = "http://www.someurl.com";
print header;
print start_html("Scalars");
print <<EndHTML;
<h2>Hello</h2><p>My e-mail address is $email, and my web url is
<a href="$url" mce_href="$url">$url</a>.</p>
EndHTML
print end_html;
Download Script

Download CGI variables Script

Related Posts

Share it!
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • email
  • LinkedIn
  • Live
  • MySpace
  • Netvibes
  • PDF
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Tumblr
  • Twitter
  • Yahoo! Bookmarks
  • Yahoo! Buzz
  • Add to favorites
  • Share/Bookmark

Post a Comment

Comment will appear here after approval, Thanks for patience