作者dxf91qqq (chris)
看板Perl
标题[请益] 如何在文件中多次跨行比对
时间Fri Feb 6 21:06:16 2015
请教各位先进
如何对文件进行多次的跨行比对?
我试了几种方法,
但结果仍然有问题;
如果在while前用$/="";的方式会变成整个文件只比对一次;
但一旦用while读文件内容就只能一次读一行,
变成比对不到想要的模式;
程式码如下:
#! \strawberry\perl\bin\perl
use warnings;
use strict;
use 5.010;
use autodie;
open FILE, "<123.txt";
while (<FILE>) #也可不写档案代码
{
if(/test_result: 1,2,3,4.*?test_name: iddq/sm)
{
print "match\n";
print $&;
}
}
close FILE;
想比对的文件123.txt内容如下:
dfklqwejpfwejkpofwkjp
test_result: 1,2,3,4
test_name: iddq
test_unit: uA
kdjkfjwojoew
gvaksljgwrl
hbrewhg
test_result: 12,22,33,44
test_name: iddq1
test_unit: uA
fgewgerjwogwrj
gwejqoej
test_result: 13,2,3,4
test_name: iddq
test_unit: uA
oljoifjwqeoijfweo
jfowejqoifjfeoi
test_result: 14,2,3,4
test_name: iddq
test_unit: uA
blahblahblahblah
[3.jpg]
栏位1 栏位2 栏位3 栏位4 资料1 资料2 资料3 资料4
[4.jpg]
blahblahblahblah
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 1.169.240.149
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Perl/M.1423227978.A.50B.html
1F:推 abliou: 档案开一次不够 你可以开两次阿? 02/06 22:49
2F:→ dxf91qqq: 在while里开吗? 02/06 23:08
3F:→ CCWck: 档案不大的话 就逐行存到阵列 之後你爱怎麽用怎麽用 02/07 00:31
4F:→ dxf91qqq: 已解决, 感谢各位先进的提示 02/07 10:28
5F:→ herculus6502: //g 02/07 14:32