我是否真的从下面的操作中获得任何好处(而不是将两个if语句中的实际正则表达式替换为$ {pcr})? (很多更行是在真实数据集,但只是用数据为例。perl预编译的正则表达式问题
my $defs = 0;
my $tests = 0;
my $pcr = qr/\s*[\/\\]?\s*/;
while (<DATA>)
{
$defs = ($1 ? 0 : 1) if /<(${pcr})definitions/;
$tests = ($1 ? 0 : 1) if /<(${pcr})tests/;
print "defs: $defs\ntests: $tests\n\n";
}
__DATA__
<what>
</what>
<definitions>
<one />
</definitions>
<tests>
<two />
<three />
</tests>
当你自己进行基准测试时会发生什么? – 2009-12-04 20:01:26
我只是想知道一般真的,因为我不太了解perl中的预编译正则表达式,在我看来,既然你把预编译正则表达式放在另一个正则表达式语句中,它无论如何都必须重新编译。 – user105033 2009-12-04 20:03:29
是的。我想知道如何找出这样的事情! – 2009-12-04 20:05:20