zoukankan      html  css  js  c++  java
  • CGI的函数

    CGI 不是语言而是common language gateway, 是借助STDIN, STDOUT来操作,简单的例子,

    #!/usr/bin/perl -wT
    print "Content-type: text/html\n\n";
    print <<EndOfHTML;
    <html><head><title>Test Page</title></head>
    <body>
    <h2>Hello, world!</h2>
    </body></html>
    EndOfHTML
    

    把以上cgi,放在www docuements的目录里,

    访问 http://www.cgi101.com/book/ch1/third.cgi

    CGI.pm Module

    The CGI.pm 模块式 Perl  5.004里面的标准库。

    use CGI qw(:standard);
    
    The qw(:standard) 表示我们从CGI.pm.调用"standard" 函数。
    
    调用函数,如果不传参数,可以不要括号,如下,
    functionname(arguments)
    
    CGI.pm有很多函数,我们可以用的如以下几个,
    
    header;
    start_html;
    end_html;
    
    例如,print start_html("Hello World");会打印出,
    <html>
    <head>
    <title>Hello World</title>
    <head>
    <body>
    
    例如,print start_html(-title=>"Hello World",
    	-bgcolor=>"#cccccc", -text=>"#999999",
     -background=>"bgimage.jpg");
    会打印出如下,
    <body bgcolor="#cccccc" text="#999999"  background="bgimg.jpg">
    
    end_html 会打印如下的标签
    
    </body>
    
    </html>
    
    因为perl是OO的,你可以完全读懂以下两段程序是一个意思,
    
    use CGI qw(:standard);
    
    print header;
    
    print start_html("Hello World");
    
    以下是OO的,
    
    use CGI;                    # don't need qw(:standard)
    $cgi = CGI->new;         # ($cgi is now the object)
    print $cgi->header;      # function call: $obj->function
    print $cgi->start_html("Hello World");
    
    再上一个完整的程序,
    
    #!/usr/bin/perl -wT
    use CGI qw(:standard);
    print header;
    print start_html("Hello World");
    print "<h2>Hello, world!</h2>\n";
    print end_html;
    
  • 相关阅读:
    Python 类中的"静态"成员变量
    Python 标准输出 sys.stdout 重定向
    [转] Python的import初探
    百度地图_路线规划,起点终点标记弹窗显示信息
    哈哈哈哈
    centos7.6安装mysql5.6
    redis集群搭建
    初学 Nginx (一) SSI 的作用
    IE 不兼容 console 关键字
    windows 安装多个版本的jdk后修改 环境变量不起作用
  • 原文地址:https://www.cnblogs.com/cosiray/p/2409735.html
Copyright © 2011-2022 走看看