一 CGI.pm中的方法(routines)调用
1. CGI.pm实现了两种使用方法,分别是面向对象的方式和传统的perlmodule方法的方式。
面向对象的方式:
 代码如下:
#!/usr/local/bin/perl -w
use CGI;   # load CGI routines
$q = CGI->new;                        # create new CGI object
print $q->header,                    # create the HTTP header
    $q->start_html('hello world'), # start the HTML
    $q->h1('hello world'),         # level 1 header
    $q->end_html;                  # end the HTML
传统的module方法的方式:
 代码如下:
#!/usr/local/bin/perl
use CGI qw/:standard/;           # load standard CGI routines
print header,                    # create the HTTP header
     start_html('hello world'), # start the HTML
     h1('hello world'),         # level 1 header
     end_html;                  # end the HTML
2. CGI.pm中的方法。
CGI.pm中的方法,通常有很多的参数,所以一般我们使用命名参数的方式来调用,例如:
 代码如下:
print $q->header(-type=>'image/gif',-expires=>'+3d');
命名参数的值可以为scalar或array reference类型,例如:
 代码如下:
$q->param(-name=>'veggie',-value=>'tomato');
$q->param(-name=>'veggie',-value=>['tomato','tomahto','potato','potahto']);
3. CGI.pm中的html元素(html shortcuts)方法
所有的html的元素(例如h1,br等)在CGI.pm中都有对应的方法,这些方法根据需要动态的生成,且都包含2个参数,第一个参数为hash类型,对应html元素的属性,第二个参数的string类型,对应html元素的内容。例如html中的h1对应的方法为h1( ):
Code              Generated HTML
----                 --------------
h1()                <h1>
h1('some','contents');             <h1>some contents</h1>
h1({-align=>left});                  <h1 align="LEFT">            
新闻热点
疑难解答