|
发表于 2012-3-8 14:58:21
|
显示全部楼层
本帖最后由 sanxia 于 2012-3-8 15:01 编辑
加一个变量,比如$comment_flag
$InFile=$ARGV[0] or die "Error! Usage: xxx.pl InFile\n";
$OutFile=$ARGV[1] or ($OutFile=$InFile . "_new") ;
open(readIn, "<$InFile") or die "Can't read the file: $InFile.\n";
open(writeOut, ">$OutFile") or die "Can't write to the file: $OutFile.\n";
my $comment_flag = 0 ;
while($line=<readIn>){
$line=~/^\s*begin\s*$/ and $comment_flag = 1 ;
if($comment_flag==1){
$line =~ s/^/**/;
}
printf( writeOut "$line");
$line=~/^\s*end\s*$/ and $comment_flag = 0 ;
}
close(writeOut);
close(readIn); |
|