perl如何将读取的文件去掉后缀名,然后再将文件名输出去? 10
如下面程序,我想将文件的后缀名去掉再输出到别的文件,怎么做?请各位大神指教my$path="f:/drl";#设置查询的目录openOUT,">f:/TMp/dd"ord...
如下面程序,我想将文件的后缀名去掉再输出到别的文件,怎么做?请各位大神指教
my $path="f:/drl"; #设置查询的目录
open OUT, ">f:/TMp/dd" or die "Can't create output file";
opendir(TEMPDIR, $path) or die "can't open it:$!";
my @dir = grep/.drl/g, readdir TEMPDIR; #筛选文件
print join "\n",@dir;
print OUT join "\n",@dir;
close TEMPDIR;
close OUT; 展开
my $path="f:/drl"; #设置查询的目录
open OUT, ">f:/TMp/dd" or die "Can't create output file";
opendir(TEMPDIR, $path) or die "can't open it:$!";
my @dir = grep/.drl/g, readdir TEMPDIR; #筛选文件
print join "\n",@dir;
print OUT join "\n",@dir;
close TEMPDIR;
close OUT; 展开
展开全部
my $path="f:/drl"; #设置查询的目录
#需要把这个文件句柄修改为可持续添加的格式 : ">>"
open OUT, ">>f:/TMp/dd" or die "Can't create output file";
opendir(TEMPDIR, $path) or die "can't open it:$!";
my @dir = grep/.drl/g, readdir TEMPDIR; #筛选文件
# 用split 对数组内每个文件进行分割,然后截取文件名,舍去后缀
foreach my $line (@dir){
$line = (split /\./,$line)[0];
print "$line\n";
print OUT "$line\n"; # 输出保存到指定文件
}
close TEMPDIR;
close OUT;
#需要把这个文件句柄修改为可持续添加的格式 : ">>"
open OUT, ">>f:/TMp/dd" or die "Can't create output file";
opendir(TEMPDIR, $path) or die "can't open it:$!";
my @dir = grep/.drl/g, readdir TEMPDIR; #筛选文件
# 用split 对数组内每个文件进行分割,然后截取文件名,舍去后缀
foreach my $line (@dir){
$line = (split /\./,$line)[0];
print "$line\n";
print OUT "$line\n"; # 输出保存到指定文件
}
close TEMPDIR;
close OUT;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询