请教各位先进
如何对文件进行多次的跨行比对?
我试了几种方法,
但结果仍然有问题;
如果在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