[Perl]文字/代码批量替换工具

2019-10-01 14:43:25王冬梅

    my $c;
    if($insensitive)
    {
        if($global)
        {
            unless($cont=~s/($match)/${$c=Cexcept($1)}$c/gi){die "$!"}
        }
        else
        {
            unless($cont=~s/($match)/${$c=Cexcept($1)}$c/i){die "$!"}
        }
    }
    else
    {
        if($global)
        {
            unless($cont=~s/($match)/${$c=Cexcept($1)}$c/g){die "$!"}
        }
        else
        {
            unless($cont=~s/($match)/${$c=Cexcept($1)}$c/){die "$!"}
        }
    }
    unless(open(OUT, ">$bo"))
    {
        if($!==2)
        {
            my $dbo=substr $bo,0,(rindex $bo,'');
            if(opendir(OUTDIR,$dbo)){closedir OUTDIR;print "n[Warn] Can not open the output file <$bo>: $!";exit}
            else
            {
                if($!==2)
                {
                    unless(pmkpath($dbo)){print "n[Warn] Can not creat the output directory <$dbo>: $!";exit}
                    unless(open(OUT,">>$bo")){print "n[Warn] Can not open the output file <$bo>: $!";exit}
                }
                else{print "n[Warn] Can not open the output directory <$dbo>: $!";exit}