如何解决Perl CGI Meta标签
| 每个http://perldoc.perl.org/CGI.html制作元标记,都会给出以下示例:print start_html(-head=>meta({-http_equiv => \'Content-Type\',-content => \'text/html\'}))
但是使用以下代码:
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
my $cgi = new CGI;
$cgi->autoEscape(undef);
$cgi->html({-head=>meta({-http_equiv => \'Content-Type\',-content => \'text/html\',-charset=>\'utf-8\'}),-title=>\'Test\'},$cgi->p(\'test\'));
我收到以下错误:
$ perl test.cgi未定义子程序
&main :: meta在test.cgi第8行调用。
我正在尝试生成以下标签:
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
解决方法
use CGI;
时,meta
子项不会自动导入。试试看
use CGI \"meta\";
(或\":all\"
)。
, #!/usr/bin/perl
use strict;
use warnings;
use CGI qw(:all);
my $cgi = new CGI;
$cgi->autoEscape(undef);
$cgi->charset(\'utf-8\');
print
$cgi->start_html(
-head => meta({-http_equiv => \'Content-Type\',-content => \'text/html\'}),-title => \'Test\'
);
但是,您是否100%确定要使用CGI进行Web开发,而不是像PSGI / Plack这样更好的东西?
, 这篇文章很老,但是解决方法很简单:meta是对象$ cgi的方法,因此将其用作方法。
你的例子
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
my $cgi = new CGI;
$cgi->autoEscape(undef);
$cgi->html({-head=>$cgi->meta({-http_equiv => \'Content-Type\',-content=>\'text/html\',-charset=>\'utf-8\'}),-title=>\'Test\'},$cgi->p(\'test\'));
我只是在meta的fromt中添加了$ cgi->。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。