我有一个名为 - "Requests"
的目录,我在文件下面
Transition-Request-201405061735.html
Requisition-Request-201405061735.html
Transition-Request-201405061735.txt
Transition-Request-201405061735.csv
output.txt
我只需要过滤Transition-Request-201405061735.txt
我到目前为止的代码是
#!/usr/bin/perl
use strict;
use warnings;
my $Request = "/tmp/Requests";
opendir(DIR, $Request) or die $!;
my @inputfiles = grep { /ion-Request-/ && \/\.txt$/ && -f "$Request/$_" } readdir(DIR);
print "@inputfiles\n";
输出如下
Transition-Request-201405061735.html Transition-Request-201405061735.csv Transition-Request-201405061735.txt Requisition-Request-201405061735.html
我正在寻求专家建议使用有效的grep
语句来过滤我想要的文件 - Transition-Request-201405061735.txt
答案 0 :(得分:1)
这是由转义字符引起的:
\/\.txt$/
# ^ here
删除它:
.... /ion-Request-/ && /\.txt$/ ...
答案 1 :(得分:1)
使用glob
:
my @inputfiles = glob '/tmp/Requests/Transition-Request-*.txt';