如何修改Perl脚本仅对含_15_模式的文件触发邮件发送
Perl代码逻辑调整实现
需求说明
原代码默认遍历所有匹配文件时,全部执行「发邮件+文件转移」操作,调整后逻辑如下:
- 仅文件名匹配
testfile_15_模式的文件(例:testfile_15_stock)发送邮件 - 其余文件正常执行转移逻辑,跳过邮件发送步骤
修改后代码
my @files = grep { -f "$source_dir/$test_label/$_" } get_file_list("$source_dir/$test_label"); foreach my $file_name (@files) { # 仅符合命名规则的文件触发邮件发送 if ($file_name =~ /^testfile_15_/) { mail_with_attachments("$source_dir/$test_label", $file_name ); } # 全量文件统一执行转移逻辑 copy_mk_subdirs("$source_dir/$test_label/$file_name" , "$target_dir/$test_label", $glb_yr , $glb_month); log_it "Bestand $source_dir/$test_label/$file_name gekopieerd naar $target_dir/$test_label/$glb_yr/$glb_month .\n"; l_move("$source_dir/$nco_label/$file_name" , "$hvr_dir/$file_name"); log_it "Bestand $source_dir/$test_label/$file_name verplaatst naar $hvr_dir .\n"; }
规则说明
- 正则
/^testfile_15_/匹配以testfile_15_开头的文件名,完全匹配需求示例的匹配规则 - 若需要匹配文件名任意位置包含
testfile_15_的场景,删除正则开头的^即可
内容的提问来源于stack exchange,提问作者Toine de L
相关产品推荐
相关产品推荐

