如何实现把perl程序嵌入.html中

如何实现把perl程序嵌入.html中,第1张

如是我闻, 我想除了 php, 好像没有第二种 CGI 语激誉吵言是把自然嵌入到 HTML 里*. 在 Perl, 我们会把 html 嵌入到 perl 里. 如:

#!perl

print "Set-Cookie: ........ \n"

print "Content-Type: text/html\n\n"

$x = 100 

$y = "Hello World"

print <<"HTML"

    <meta http-equiv="Content-Type" Content="text/htmlcharset=utf-8">

    <title>Hello World!</title>

    <body bgcolor=black text=white> 虚乱   

   明侍 我想说 $y $x 遍

HTML

print $y for ( 1..$x )

* 如果您真的要勉强地内嵌 perl 到 html中, 另一门迳是用 SSI 的介面 (Server Side Included), 一般会存档成 .shtml , 但这界面会因不同的伺服器实例而没有统一 *** 作情况, 因此移植性很低, 又容易有安全隐患, 所以其实也不建议使用

最直接的就是print html code,当然比较繁琐,一般多用模块实现,比较常用的是CGI模块,例如:

#!/usr/bin/perl

use CGI

my 慎携扒$q = CGI->new

#print $q->header()

print $q->start_html('hello world')

print $q->h1('hello world')

print $q->end_html

输出:

<!DOCTYPE html

    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

     "

<html xmlns="

<head>

<title>hello world</title>

<meta http-equiv="Content-Type" content="text/html charset=iso-8859-1" />

</head>

<body>

<h1>hello world</h1>

</body>

</html>

print $q->header()主要宽昌是为了CGI程序用,如果只是要生成html代码就不用了隐腔。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12538692.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存