perl-cgi基础

本文介绍如何使用Perl CGI编写简单的网页交互程序,包括获取并处理GET参数,展示参数值,并提供HTML页面的初步展示。

代码: 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();  


完! 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值