【发布时间】:2016-08-26 16:31:02
【问题描述】:
我必须修复一个 Perl 脚本,该脚本执行以下操作:
# Get the list of files in the staging directory; skip all beginning with '.'
opendir ERR_STAGING_DIR, "$ERR_STAGING" or die "$PID: Cannot open directory $ERR_STAGING";
@allfiles = grep !/^$ERR_STAGING\/\./, map "$ERR_STAGING/$_", readdir(ERR_STAGING_DIR);
closedir(ERR_STAGING_DIR);
我有两个目录,一个是STAGING,另一个是ERROR。 STAGING 包含 ABC_201608100000.fin 之类的文件,ERR_STAGING_DIR 包含 ABC_201608100000.fin.bc_lerr.xml。现在 Perl 脚本作为守护进程运行,它不断在ERR_STAGING_DIR 目录中查找文件并处理错误文件。
但是,如果ABC_201608100000.fin 存在于 STAGING 中,我的要求是不要处理该文件。
问题:
有没有办法,我可以过滤allfiles数组并选择STAGING目录中不存在的文件?
我尝试了什么:
我已经通过编程方式忽略了 STAGING 目录中存在的文件。虽然它不起作用。
# Move file from the staging directory to the processing directory.
@splitf = split(/.bc_lerr.xml/,basename($file));
my $finFile = $STAGING . "/" . $splitf[0];
print LOG "$PID: Staging File $finFile \n";
foreach $file(@sorted_allfiles) {
if ( -e $finFile )
{
print LOG "$PID: Staging File still exist.. moving to next $finFile \n";
next;
}
# DO THE PROCESSING.
【问题讨论】:
标签: perl