use warnings;
use File::Find;
my $srceDir = "//mnt/Share_Drive/Verizon PM&T/Capture Files/";
opendir(DIR, $srceDir) or die "Can't open $srceDir: $!";
my @files = (find -type f -newermt "12 Feb 2013", $srceDir);
closedir(DIR);
我可以在 Linux 中find
使用该-newermt
选项运行该命令,但是当我将其放入 perl 脚本中时,出现以下错误,您能帮忙吗?谢谢
String found where operator expected at ./queryAlm.pl line 11, near "newermt "12 Feb 2013""
(Do you need to predeclare newermt?)
syntax error at ./queryAlm.pl line 11, near "newermt "12 Feb 2013""
答案1
perlFile::Find
模块与该命令几乎没有关系find
。请参阅perldoc File::Find
如何使用它。
正如 jordanm 指出的,您可以使用find2perl
来帮助您编写perl
代码,但请注意,它find2perl
仅识别标准find
语法,因此通常不识别 BSD/GNU 扩展,例如-newermt
.您必须自己编写 perl 代码(调用stat()
该文件并将其mtime
与进行比较POSIX::mktime(0,0,0,12,2,113)
)。
要运行该find
命令,您不需要该File::Find
模块,只需执行以下操作:
my $srceDir = "//mnt/Share_Drive/Verizon PM&T/Capture Files/";
my @find_cmd = ("find", $srceDir, "-type", "f", "-newermt", "12 Feb 2013", "-print0");
open FIND, "-|", @find_cmd;
$/ = "\0";
my @files = <FIND>; chomp @files;
my $ret = close FIND or warn $! ?
"Error closing find pipe: $!" :
"find exited with non-zero exit status: $?";