我注意到我的Ruby(1.9)脚本中存在一些极度延迟,经过一些挖掘后,它归结为正则表达式匹配。我在Perl和Ruby中使用以下测试脚本:Perl:$fname=shift(@ARGV);open(FILE,"){if(/(.*?)\|.*?SENDINGREQUEST.*?TID=(.*?),/){print"$1:$2\n";}}ruby:f=File.open(ARGV.shift)while(line=f.gets)if/(.*?)\|.*?SENDINGREQUEST.*?TID=(.*?),/.match(line)puts"#{$1}:#{$2}"endend我对两个脚本使
选择有意义。但是有人可以向我解释.detect吗?我不明白这些数据。>>[1,2,3,4,5,6,7].detect{|x|x.between?(3,4)}=>3>>[1,2,3,4,5,6,7].detect{|x|x.between?(3,6)}=>3>>[1,2,3,4,5,6,7].detect{|x|x.between?(3,7)}=>3>>[1,2,3,4,5,6,7].detect{|x|x.between?(2,7)}=>2>>[1,2,3,4,5,6,7].detect{|x|x.between?(1,7)}=>1>>[1,2,3,4,5,6,7].detect{|x