国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Perl > 正文

perl的cgi高級編程介紹

2020-06-04 20:28:37
字體:
來源:轉載
供稿:網友

一 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">

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 钦州市| 元朗区| 册亨县| 平遥县| 庆安县| 新闻| 义乌市| 台山市| 宜丰县| 焉耆| 徐汇区| 郁南县| 沁水县| 合水县| 贵德县| 蒙自县| 株洲县| 西乌珠穆沁旗| 保德县| 潞西市| 利辛县| 陆川县| 德令哈市| 云梦县| 衡阳市| 孟津县| 都江堰市| 南乐县| 阜宁县| 松江区| 温泉县| 黔江区| 高青县| 长白| 聂荣县| 彩票| 永德县| 木里| 三亚市| 大渡口区| 泸定县|