#!/usr/bin/perl -w
# prints dir list of .jpg filenames to screen
# and adds HTML markup for flexbox
use 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 period
next 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 title
my $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;
这是我现在得到的前 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 = '">'; 我已经尝试了无数版本——这只是当前的一个。
我想知道如何使这两个字符显示在行的末尾而不是下一行的开头。
我在这件事上花了几个小时,前天还花了两个小时试图让论坛接受我的问题。
缥缈止盈
莫回无
吃鸡游戏
相关分类