一 CGI.pm中的方法(routines)调用
[b]1. CGI.pm实现了两种使用方法,分别是面向对象的方式和传统的perlmodule方法的方式。
[/b]面向对象的方式:
[url=fred.html]
[b]二 CGI.pm中获取cgi的参数
[/b]@names = $query->param #get all params
@values = $query->param('foo'); #get param foo as list
$value = $query->param('foo'); #get param foo as scalar
param()获取参数的结果可以为scalar或array类型,例如当参数的结果来自多选的scrollinglist的时候就为array类型。如果参数的值在querystring中没有给定("name1=&name2="),param()将返回emptystring。如果参数在querystring中根本不存在,则param()则返回undef或emptylist。当参数为多个值时querystring中写法为var1=value1&var1=value2&var1=value3.
[b]三 header and start_html
[/b]1. header指定html的header,例如
print header; # 返回默认的type:text/html
print header('image/gif'); #设定type为:image/gif
print header('text/html','204 No response');
$cookie1 = $q->cookie(-name=>'riddle_name', -value=>"The Sphynx's Question");
$cookie2 = $q->cookie(-name=>'answers', -value=>\%answers);
print header(-type=>'image/gif',
-nph=>1,
-status=>'402 Payment required',
-expires=>'+3d',
-cookie => [$cookie1,$cookie2] ,
-charset=>'utf-7',
-attachment=>'foo.gif',
-Cost=>'$2.00');
其中-type,-status,-expires,-cookie为可以设别的参数,其他的命名参数都被转化为html header属性。
-expires的值可以为:
+30s 30 seconds from now
+10m ten minutes from now
+1h one hour from now
-1d yesterday (i.e. "ASAP!")
now immediately
+3M in three months
+10y in ten years time
Thursday, 25-Apr-1999 00:40:33 GMT at the indicated time & date
2. start_html 创建页面的顶层元素<html><header</header><body>
例如:
[url=http://search.cpan.org/~markstos/CGI.pm-3.60/lib/CGI.pm]http://search.cpan.org/~markstos/CGI.pm-3.60/lib/CGI.pm[/url]