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

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

$replacemen=~s/?/?/g;
}

sub cFile
{
    my $fi;
    ($fi)=@_;
    if(opendir(DIR, $fi))
    {
        my @dir=readdir(DIR);
        closedir DIR;
        if("" eq substr $fi,(length $fi)-1){$fi=substr($fi,0,(length $fi)-1)}
        my @subdirs= grep { /^(?!.)/ && -d "$fi$_" } @dir;
        foreach my $subdir (@subdirs)
        {
            cFile("$fi$subdir")
        }
        @files = grep { /$checktyp/i  && -T "$fi$_" } @dir;
        foreach my $fil (@files)
        {
            my $bp='';
            $bp=(substr $fi,(length $gi))."";
            my $bi="$fi$fil";
            my $bo=$go.$bp.$fil;
            remove($bi,$bo)
        }
    }
}
unless("" eq substr $go,(length $go)-1){$go.=""}
if(-d $gi)
{
    unless("" eq substr $gi,(length $gi)-1){$gi.=""}
    cFile($gi);
}
else
{
    my $bu=substr $gi,(rindex $gi,'');
    my $bo=$go.$bu;
    remove($gi,$bo)
}

print "nProcess Finished!";
print "n-i:$gi";
print "n-o:$go";
print "n-m:$match";
if($except){print "n-e:$except"}
if($replacement){print "n-r:$replacement"}
sub remove
{
    my $bi;
    my $bo;
    ($bi,$bo)=@_;

    print "nprocessing $bi ...n";
    unless(open(INPUT,"<$bi")){print "n[Warn] Can not open the file <$bi>: $!";return}
    my @conts = <INPUT>;
    close INPUT;
    my $cont=join '',@conts;