perl-cgi基础

代码: http://xxxxx/cgi/perl-cgi.cgi?name=itech&url=itech.cnblogs.com&p1=test1

#!/usr/bin/perl -wT

#should use strict and warnning

use warnings;

use strict;

use CGI;

#to debug error

use CGI::Carp qw(warningsToBrowser fatalsToBrowser);

#or debug from command line by : perl -cwT yourcgi.cgi

#or debug by : tail /var/log/apache/error_log

#make sure yourcgi.cgi is world excutable or 755 permission

#just include sub features of cgi, standard means, 'html2', 'html3', 'html4', 'form' and 'cgi'.

#use CGI qw(:standard);

#must define and initialize

my $p1='';

my $p2='';

my $name='';

my $url='';

my $q = new CGI;

$p1 = $q->param('p1') if $q->param('p1');

$p2 = $q->param('p2') $q->param('p2') ;

$name = $q->param('name') $q->param('name') ;

$url = $q->param('url') $q->param('url');

print $q->header();

print $q->start_html(-title=>"Hello World");

print "p1:$p1<br>";

print "p2:$p2<br>";

if(!defined($p2)){print "p2 is not defined<br>";}

if($p2 eq ""){print "p2 is empty<br>";}

print <<EndHTML;

<h2>Hello</h2>

<p>

My name is $name, and my web url is

<a href="$url">$url</a>.

</p>

EndHTML

$q->h3('welcome to here!<br>');

print "$ENV{REMOTE_ADDR}<br>";

print $q->end_html();

完!