这段代码:
#!/bin/perl
BEGIN { $/ = undef; };
open (FILE,"file.txt") || die "Cannot open $FILE:$!";
while (<FILE>) {
my @matches;
if ( m#SelectEditPolicy\.do\?policyID=[0-9]{1,4}.*?">(.*?)</a>#sg) {
push (@matches,$1);
}
foreach $rec (@matches) {
print "$rec\n";
}
}
针对这个文件:
>cat file.txt
SelectEditPolicy.do?policyID=2958')">
Test123 OLD</a>
SelectEditPolicy.do?policyID=6643')">
Test123 </a>
执行 file.pl 仅返回第一个匹配项。我已经阅读了尽可能多的帖子,但没有任何成功?
我究竟做错了什么?