perl-cgi基础

来源:

http://www.cnblogs.com/itech/archive/2012/09/22/2698553.html

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

 1 #!/usr/bin/perl -wT
 2 #should use strict and warnning
 3 use warnings;
 4 use strict;
 5 use CGI;
 6 #to debug error
 7 use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
 8 #or debug from command line by : perl -cwT yourcgi.cgi
 9 #or debug by : tail /var/log/apache/error_log
10 #make sure yourcgi.cgi is world excutable or 755 permission
11 
12 #just include sub features of cgi, standard means, 'html2', 'html3', 'html4', 'form' and 'cgi'.
13 #use CGI qw(:standard);
14 
15 
16 #must define and initialize
17 my $p1='';
18 my $p2='';
19 my $name='';
20 my $url='';
21 my $q = new CGI;
22 $p1   = $q->param('p1') if $q->param('p1');
23 $p2   = $q->param('p2') $q->param('p2') ;
24 $name = $q->param('name') $q->param('name') ;
25 $url  = $q->param('url') $q->param('url');
26 
27 print $q->header();
28 print $q->start_html(-title=>"Hello World");
29 
30 print "p1:$p1<br>";
31 print "p2:$p2<br>";
32 if(!defined($p2)){print "p2 is not defined<br>";}
33 if($p2 eq ""){print "p2 is empty<br>";}
34 
35 print <<EndHTML;
36 <h2>Hello</h2>
37 <p>
38 My name is $name, and my web url is
39 <a href="$url">$url</a>.
40 </p>
41 EndHTML
42 
43 $q->h3('welcome to here!<br>');
44 print "$ENV{REMOTE_ADDR}<br>";
45 print $q->end_html();

完! 

原文地址:https://www.cnblogs.com/spriteflk/p/5735958.html