#!/usr/bin/perl
print "Content-type: text/html\n\n";
print <<'EOF';
<!DOCTYPE html>
<html><head><title>Perl CGI 輸出 HTML</title></head>
<body>
<h1>Hello from Perl!</h1>
<img src="$gif/top.gif" alt="Logo" />
</body></html>
EOF
exit;
print "Content-type: text/html\n\n":HTTP 標頭,**雙換行結束**<<'EOF':單引號 Here-Doc,**不插值變數**,適合大段靜態 HTML<<"EOF"(雙引號)或 <<EOFsub html_page {
print "Content-type: text/html\n\n";
print <<'HTML';
... HTML 內容 ...
HTML
exit;
}
問題:相對路徑 resource/top.gif 在 CGI 執行目錄下可能失效。
setup.cgi(實為 .pl 模組)# setup.cgi
$gif = 'https://your.domain.com/resource'; # 單引號,純字串
1; # 模組必須返回真值
require "setup.cgi"; # 載入設定
print <<"HTML"; # 雙引號 Here-Doc,插值 $gif
<img src="$gif/top.gif" alt="Logo" />
HTML
use CGI qw(:standard);
print header(-charset => 'utf-8'),
start_html(-title => 'Perl CGI'),
h1('Hello'),
img({-src => "$gif/top.gif", -alt => 'Logo'}),
end_html;
escapeHTML 自動轉義param()、檔案上傳、Cookie 管理chmod 755 script.cgi#!/usr/bin/perlExecCGI、AddHandler cgi-script .cgi .pltail -f /var/log/apache2/error.log