3 回答

TA貢獻1865條經(jīng)驗 獲得超7個贊
有數(shù)百種方法可以解決這個問題,其中之一是:
您的示例中的 $mylist (打印之前)包含:
<img src="out-of-the-night.jpg" style="width:100%"> title = "Out of the Night ">
刪除中間的換行符,并將其添加到字符串的末尾
$mylist =~ s/[\r\n]+//; $mylist .="\n";
會解決這個問題。
順便說一句: $last 末尾的 '> "' 似乎也是錯誤的。

TA貢獻1829條經(jīng)驗 獲得超7個贊
請看看您是否發(fā)現(xiàn)以下代碼有用。
它在本地目錄中查找 JPG 文件并生成網(wǎng)頁
use strict;
use warnings;
use feature 'say';
my $dir = '.';
my @files;
push @files, $_ while glob('*.jpg');
my $title = 'Pictures in JPEG format';
my $space = "\n\t\t\t";
my $style = 'width:100%';
my $html = '
<html>
<head>
<title>$title</title>
</head>
<body>';
for (@files) {
/(.*?)\.jpg/;
my $title = $1;
$title =~ s/[-_]/ /g;
$html .= "$space title = \"\u$title\"";
$html .= "$space<img src=\"$_\" style=\"$style\">";
}
$html .= '
</body>
</html>';
say $html;
輸出
<html>
<head>
<title>Pictures in JPEG format</title>
</head>
<body>
title = "File 08"
<img src="file-08.jpg" style="width:100%">
title = "File 09"
<img src="file-09.jpg" style="width:100%">
title = "File 01"
<img src="file_01.jpg" style="width:100%">
title = "File 02"
<img src="file_02.jpg" style="width:100%">
title = "File 03"
<img src="file_03.jpg" style="width:100%">
</body>
</html>
- 3 回答
- 0 關注
- 133 瀏覽
添加回答
舉報