• 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
    

  • 相关阅读:
    idea设置tomcat虚拟路径的两种方法
    改变javahome但是java version并没有修改的解决方案
    1. 两数之和
    88. 合并两个有序数组
    53. 最大子数组和(欠分治法)
    【记录】orcle安装
    191. 位1的个数
    【记录】plsql安装
    IP2region离线解析IP地址
    flink 常用命令
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351220.html
Copyright © 2020-2023  润新知