zhuzhu1107 发表于 2019-02-28 19:08

文本中提取匹配信息。



文本格式如下,判断lu_name,提取lu_name对应的plu_name,请问大神们用perl怎么实现啊?

第一个AAA 判断是No records, 不用提取了。
第二个BBB 对应的plu_name分别是xxx跟yyy,返回两个数组,BBB, xxx和BBB,yyy

lu_name = AAA

------------------------------------------------------------------------
list_options = FIRST_IN_LIST
No records found matching this query.

------------------------------------------------------------------------
lu_name = BBB

------------------------------------------------------------------------
list_options = FIRST_IN_LIST

plu_alias = ""
plu_name = xxx
description = ""

plu_alias = ""
plu_name = yyy
description = ""

------------------------------------------------------------------------
lu_name = TEST

------------------------------------------------------------------------
list_options = FIRST_IN_LIST
No records found matching this query.





目前只写出匹配lu_name的, 提取出值来

//


foreach $line (@contents) {
      next if ($line=~m/-----/);   # Do not display seperaters

      if ($line=~m/lu_name/) {
            @data = split(/=/,$line);
            $data=~s/^\s+|\s+$//g;   # This removes all blank characters
            push @lu_name, $data;
            next;
            }
}


jason_w 发表于 2019-03-04 17:44

$line=~m/lu_name/;
my $match = $&;
页: [1]
查看完整版本: 文本中提取匹配信息。