由于工作需要,需要批量建立网站,修改配置文件。开始时用sed去批量修改的,最后改装成perl了。
#!/usr/bin/perl
while(<>){
chomp;
@line=split(/\s+/,$_);
open FH,"< /home/test/$line[0]/wp-config.php";
my @webfile;
while(<FH>){
        s/(ME|ER)', 'root/$1', '$line[1]/g;
        push @webfile,$_;
}
close FH;
open FH,"> /home/test/$line[0]/wp-config.php";
print FH for @webfile; #相当于foreach $mm (@webfile){
                               #     print FH $mm;        
                                #   
                                #       }
close FH;

}
输入的文件
域名      数据库名称
a1.com       a1_db
a2.com        a2_db