|
|
1
6
为什么使用正则表达式会“过分”呢?许多人担心Perl中的正则表达式过于死板,因为他们认为运行它们需要一个高度复杂且缓慢的正则表达式算法。这并不总是正确的:实现是高度优化的,并且许多简单的情况都经过了特殊处理:看起来像正则表达式的东西实际上可以执行简单的子字符串搜索。如果这种情况发生,我一点也不会感到惊讶
我推荐
OTOH,如果正则表达式只是因为语法难看而被“过度使用”,那么我就太主观了,不能说任何话 |
|
|
2
9
各种示例和速度比较。我想看看有些方法在每个字符上拆分字符串的速度有多快可能是个好主意。
Perl v5.10.0Rate split-capture match-capture map-substr match unpack split split-string split-capture 296/s -- -20% -20% -23% -58% -63% -63% match-capture 368/s 24% -- -0% -4% -48% -54% -54% map-substr 370/s 25% 0% -- -3% -48% -53% -54% match 382/s 29% 4% 3% -- -46% -52% -52% unpack 709/s 140% 93% 92% 86% -- -11% -11% split 793/s 168% 115% 114% 107% 12% -- -0% split-string 795/s 169% 116% 115% 108% 12% 0% -- PerlV5.10.1Rate split-capture map-substr match-capture match unpack split split-string split-capture 301/s -- -31% -41% -47% -60% -65% -66% map-substr 435/s 45% -- -14% -23% -42% -50% -50% match-capture 506/s 68% 16% -- -10% -32% -42% -42% match 565/s 88% 30% 12% -- -24% -35% -35% unpack 743/s 147% 71% 47% 32% -- -15% -15% split 869/s 189% 100% 72% 54% 17% -- -1% split-string 875/s 191% 101% 73% 55% 18% 1% -- Rate split-capture match-capture match map-substr unpack split-string split split-capture 300/s -- -28% -32% -38% -59% -63% -63% match-capture 420/s 40% -- -5% -13% -42% -48% -49% match 441/s 47% 5% -- -9% -39% -46% -46% map-substr 482/s 60% 15% 9% -- -34% -41% -41% unpack 727/s 142% 73% 65% 51% -- -10% -11% split-string 811/s 170% 93% 84% 68% 12% -- -1% split 816/s 171% 94% 85% 69% 12% 1% --
如你所见
分裂
所以我建议你和老朋友一起去
|
|
|
3
5
没有比使用
|
|
|
4
5
对于可读性较差且更简洁的(仍然使用regex overkill):
(这个成语我是从打高尔夫中学来的。) |
|
5
4
你说得对。做这件事的标准方法是
|
|
|
7
2
使用
您可能需要包括
|
|
|
Carsten · 使用最近的搜索模式更改文本块 1 年前 |
|
|
A.Ellett · 测试-t STDIN与-t<STDIN> 1 年前 |
|
|
con · 如何跳转到foreach迭代的特定点? 1 年前 |