Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html perl脚本不关闭正文?_Html_Perl_Tags - Fatal编程技术网

Html perl脚本不关闭正文?

Html perl脚本不关闭正文?,html,perl,tags,Html,Perl,Tags,在打印HTML的示例脚本中,我认为body标记没有关闭。然而,我以前从未有过使用Perl的经验。这个例子不正确吗?还是有什么东西意味着身体是封闭的 print "Content-type: text/html\n\n"; print "<html>\n<head>\n<title>\nPerl CGI Example\n</title>\n<body>\n<h1>Hello, World!</h1>\nYour

在打印HTML的示例脚本中,我认为body标记没有关闭。然而,我以前从未有过使用Perl的经验。这个例子不正确吗?还是有什么东西意味着身体是封闭的

print "Content-type: text/html\n\n";
print "<html>\n<head>\n<title>\nPerl CGI
Example\n</title>\n<body>\n<h1>Hello,
World!</h1>\nYour user agent is: <b>\n";
print $cgi_object->user_agent();
print "<b>.</html>\n";
print“内容类型:text/html\n\n”;
打印“\n\n\n ERL CGI”
示例\n\n\n Hello,
世界!\n您的用户代理是:\n”;
打印$cgi_对象->用户_代理();
打印“\n”;

在最后一行有一个
的地方,在我看来应该是

您没有遗漏任何东西,该代码只是没有为body元素生成结束标记,而是生成该标记(与缺少的Doctype不同)在HTML中是可选的,因此当浏览器解析HTML元素的结束标记时,该元素将被关闭

最好是这样写:

#!/usr/bin/env perl

use strict;
use warnings;
use CGI;
use Template;

my $cgi = CGI->new();
print $cgi->header(-charset => 'utf-8');
my $ua = $cgi->user_agent();

my $tt = Template->new();

$tt->process(\*DATA, { ua => $ua });

__END__
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Perl CGI Example</title>
    </head>
    <body>
        <h1>Hello, World!</h1>
        <p>Your user agent is: <em>[% ua | html %]</em>.</p>
    </body>
</html>
#/usr/bin/env perl
严格使用;
使用警告;
使用CGI;
使用模板;
my$cgi=cgi->new();
打印$cgi->标题(-charset=>'utf-8');
my$ua=$cgi->user_agent();
我的$tt=模板->新建();
$tt->process(\*数据,{ua=>$ua});
__结束__
Perl CGI示例
你好,世界!
您的用户代理是:[%ua | html%]


如果您放弃CGI而使用它,则更好。

这里文档将是定义文本的另一个选项