加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

为什么Perl CGI模块使用连字符来启动命名参数?

发布时间:2020-12-15 23:28:53 所属栏目:大数据 来源:网络整理
导读:我是新手.我的问题是密钥(类型,到期名称等)代表什么是“ – ”?为什么不使用普通的哈希表方式并丢弃连字符? # #!/usr/local/bin/perl -wuse CGI; $q = CGI-new; print $q-header(-type='image/gif',-expires='+3d');$q-param(-name='veggie',-value='tomat
我是新手.我的问题是密钥(类型,到期名称等)代表什么是“ – ”?为什么不使用普通的哈希表方式并丢弃连字符?

# #!/usr/local/bin/perl -w
use CGI; 
$q = CGI->new; 
print $q->header(-type=>'image/gif',-expires=>'+3d');
$q->param(-name=>'veggie',-value=>'tomato');

解决方法

作者已经解释了 in the documentation.

Most CGI.pm routines accept several
arguments,sometimes as many as 20
optional ones! To simplify this
interface,all routines use a named
argument calling style that looks like
this:

print
$q->header(-type=>’image/gif’,-expires=>’+3d’);

Each argument name is preceded by a
dash. Neither case nor order matters
in the argument list. -type,-Type,
and -TYPE are all acceptable. In
fact,only the first argument needs to
begin with a dash. If a dash is
present in the first argument,CGI.pm
assumes dashes for the subsequent
ones.

Several routines are commonly called
with just one argument. In the case
of these routines you can provide the
single argument without an argument
name. header() happens to be one of
these routines. In this case,the
single argument is the document type.

print $q->header(‘text/html’);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读