Perl 提取文本中需要的值
文本格式如下,判断lu_name返回的结果是不是Norecords,提取lu_name对应的plu_name,最后返回数组lu_name跟plu_name.下面这段文本最...
文本格式如下, 判断lu_name返回的结果是不是No records, 提取lu_name对应的plu_name,最后返回数组lu_name跟plu_name.
下面这段文本最后返回结果应该是 BBB, zzz和BBB,yyy
请问大神们用perl怎么实现啊?
第一个AAA 判断是No records, 不用提取了。
第二个BBB 对应的plu_name分别是zzz跟yyy,
返回两个数组,BBB, zzz和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 = zzz
description = ""
plu_alias = ""
plu_name = yyy
description = ""
----------------------------------------------------------
lu_name = TEST
----------------------------------------------------------
list_options = FIRST_IN_LIST
No records found matching this query. 展开
下面这段文本最后返回结果应该是 BBB, zzz和BBB,yyy
请问大神们用perl怎么实现啊?
第一个AAA 判断是No records, 不用提取了。
第二个BBB 对应的plu_name分别是zzz跟yyy,
返回两个数组,BBB, zzz和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 = zzz
description = ""
plu_alias = ""
plu_name = yyy
description = ""
----------------------------------------------------------
lu_name = TEST
----------------------------------------------------------
list_options = FIRST_IN_LIST
No records found matching this query. 展开
展开全部
#!/sw/bin/perl
$txt = <<TXT;
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 = zzz
description = ""
plu_alias = ""
plu_name = yyy
description = ""
----------------------------------------------------------
lu_name = TEST
----------------------------------------------------------
list_options = FIRST_IN_LIST
No records found matching this query.
TXT
undef @list;
#分组
my @txt = split(/\nlu_name\s+\=\s+/,$txt);
#不要No records
my @lu = grep !/No records/,@txt;
#获取lu plu
my $i = 0;
my $ii = $#lu;
while($i <= $ii){
my @luplu = split(/\n/,$lu[$i]);
my $lu = $luplu[0];
my $o = 0;
my $oo = $#luplu;
while($o <= $oo){
if($luplu[$o] =~/^plu_name\s+\=\s+(\w+)/){
my $plu = $1;
push(@list,"$lu,$plu")
}
$o++;
}
$i++;
}
print"@list\n";
望采纳!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |