[请益] 如何在文件中多次跨行比对

楼主: dxf91qqq (chris)   2015-02-06 21:06:16
请教各位先进
如何对文件进行多次的跨行比对?
我试了几种方法,
但结果仍然有问题;
如果在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
作者: abliou (愚者)   2015-02-06 22:49:00
档案开一次不够 你可以开两次阿?
楼主: dxf91qqq (chris)   2015-02-06 23:08:00
在while里开吗?
作者: CCWck (干嘛要暱称)   2015-02-07 00:31:00
档案不大的话 就逐行存到阵列 之后你爱怎么用怎么用
楼主: dxf91qqq (chris)   2015-02-07 10:28:00
已解决, 感谢各位先进的提示
作者: herculus6502 (金麟岂是池中物)   2015-02-07 14:32:00
//g

Links booklink

Contact Us: admin [ a t ] ucptt.com