免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3719 | 回复: 1
打印 上一主题 下一主题

文本中提取匹配信息。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 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[1]=~s/^\s+|\s+$//g;   # This removes all blank characters
            push @lu_name, $data[1];
            next;
            }
}


论坛徽章:
0
2 [报告]
发表于 2019-03-04 17:44 |只看该作者
$line=~m/lu_name/;
my $match = $&;
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP