You need to enable JavaScript to run this app. 如何修改Perl脚本仅对含_15_模式的文件触发邮件发送
优惠活动
大模型
产品
解决方案
定价
更多

如何修改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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.14 01:09:03