第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

perl -- 在連接末尾添加雙引號和直角括號

perl -- 在連接末尾添加雙引號和直角括號

BIG陽 2023-10-24 20:47:01
#!/usr/bin/perl -w# prints dir list of .jpg filenames to screen# and adds HTML markup for flexboxuse strict;use warnings;use Text::Autoformat;my $file;my $nfilename;my $first = '<img src="';my $last = '" style="width:100%"> ';my $title = 'title = "';my $estr = '">';my $dir = "/home/clair/cp-perl/";my $mylist;opendir(DIR, $dir) or die $!;while ($file = readdir(DIR)) {# Use a regular expression to ignore files beginning with a periodnext if ($file =~ m/^\./);next if (substr $file, -1) ne "g";#***************************************# get rid of extension and replace hyphen with space   $nfilename=$file;$nfilename=~s/.jpg//;$nfilename =~ s/-/ /g;# ****************************************#capitalizewords in filename to be a titlemy $formatted = autoformat $nfilename, { case => 'highlight' };chomp($nfilename);# ****************************************$mylist = join("",$first, $file, $last, $title, $nfilename, $estr);# ************************* # thanks to George Mavridis - stackoverflow$mylist =~ s/[\r\n]+//;$mylist .="\n";# *************************print $mylist;}closedir(DIR);exit 0;這是我現(xiàn)在得到的前 3 行輸出:<pre><img src="out-of-the-night.jpg" style="width:100%"> title = "Out of the Night"><img src="homage-to-borgeson.jpg" style="width:100%"> title = "Homage to Borgeson"><img src="autumn-in-vermont.jpg" style="width:100%"> title = "Autumn in Vermont</pre>前兩個字符應該位于行的末尾,如下所示:<pre><img src="out-of-the-night-sm.jpg" style="width:100%"> title = "Out of the Night"><img src="homage-to-borgeson.jpg" style="width:100%"> title = "Homage to Borgeson"><img src="autumn-in-vermont-sm.jpg" style="width:100%"> title = "Autumn in Vermont"></pre>這是連接線:$mylist = join("",$first, $file, $last, $title, $nfilename, $estr);print $mylist;這是 $estr 聲明: my $estr = '">'; 我已經(jīng)嘗試了無數(shù)版本——這只是當前的一個。我想知道如何使這兩個字符顯示在行的末尾而不是下一行的開頭。我在這件事上花了幾個小時,前天還花了兩個小時試圖讓論壇接受我的問題。
查看完整描述

3 回答

?
縹緲止盈

TA貢獻2041條經(jīng)驗 獲得超4個贊

中的字符串$nfilename顯然以換行符結尾。您是否從文件中讀取了一行并保留了換行符?chomp可用于從變量中刪除尾隨換行符。



查看完整回答
反對 回復 2023-10-24
?
莫回無

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 末尾的 '> "' 似乎也是錯誤的。


查看完整回答
反對 回復 2023-10-24
?
吃雞游戲

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>


查看完整回答
反對 回復 2023-10-24
  • 3 回答
  • 0 關注
  • 133 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號