while continue 更新文件

zjzc01:/root/dbi# cat a1.pl 
my $a = $ARGV[0];

my $b = $ARGV[1];

my $c = $ARGV[2];

my $d = $ARGV[3];

my $f = $ARGV[4];

my $g = $ARGV[5];

open MEGADATA , ">>a.txt" or dir $!;

my $record = join (":",$a,$b,$c,$d,$e,$f,$g);
print MEGADATA "$record
";

zjzc01:/root/dbi# cat a.txt 
::::::
a:b:c:d::e:

##########下面脚本不匹配直接跳过,continue写入,匹配进行修改,在continue里写入:



用术语来解释的话,就是说,Q 取消所有元字符的含义直到遇见 E 为止。

zjzc01:/root/dbi# cat a.txt 
a:b:c:d:e
1:2:3:4:5


zjzc01:/root/dbi# cat a2.pl 
my $megalithFile = $ARGV[0];

my $siteName = $ARGV[1];

my $siteMapRef = $ARGV[2];

my $tempFile = "tmp.$$";

open MEGADATA ,"<$megalithFile" or die $!;

open TMPEGADATA ,">>$tempFile" or die $!;

while (<MEGADATA>){

##不匹配跳过,不修改,下面continue写入
print "$_ is $_
";
next unless m/^Q$siteName:/;

my($name,$location,$mapref,$type,$description) = split(/:/,$_);

##跳过如果 $siteName 不等于$name
next unless $siteName eq $name;

$mapref=$siteMapRef;

$_=join(":",$name,$location,$mapref,$type,$description);
print "$_ is $_
";
}
continue { print TMPEGADATA $_."
"
};

修改后为:
zjzc01:/root/dbi# cat tmp.22884 
a:b:x:d:e

1:2:3:4:5

原文地址:https://www.cnblogs.com/hzcya1995/p/13351220.html