#!/usr/bin/perl -w use strict; ############ while嵌套循环,内循环中需要打开的文件在内循环中打开 my $ori_mc_config="c:\\tower\\lmsetup\\mc_config_org.txt"; my $mc_config="c:\\tower\\lmsetup\\mc.txt"; my $newfile="c:\\tower\\lmsetup\\mc_config.txt"; #open OLD, "$ori_mc_config"|| die "can't open the file $!"; open NEWF ,">$mc_config"||die "can't open the fiel $!"; open NEWP ,$newfile; while(my $line=){ #print $line; if($line=~/^[A-Z]/){ #print out comment lines.If the line start with character A~Z(may commond line) $line=~/=/; my $d=$`; open OLD, "$ori_mc_config"|| die "can't open the file $!";#内循环中打开文件句柄,如果在外循环中打开,则只匹配一次即退出 while(my $old=){ #check old files the configration lines if($old=~/^[A-Z]/){ if ($old=~/$d/){ # print $old; } } } close OLD; } else {print $line;} #comment lines }