我无法复制您的问题。
$ perl -wle'
$all = "foo\n A, x\nmeow";
$all =~ s/^ *[A-Z], [a-z]\n//mg;
print $all;
'
foo
meow
$ perl -wle'
$all = "foo\n A, x\nmeow";
$all =~ s/^ *\p{Lu}, \p{Ll}\n//mg;
print $all;
'
foo
meow
测试使用5.8.8、5.10.1、5.12.4(线程)和5.16.0在Linux上进行。
最佳猜测:pos($all)
不为零。也许你做了一些傻事,比如 if ($all =~ /.../g)
。
一开始我也无法去除空格来重现此问题。
$ perl -wle'
$all = "foo\nA, x\nmeow";
$all =~ s/^ *[A-Z], [a-z]\n//mg;
print $all;
'
foo
meow
$ perl -wle'
$all = "foo\n A, x\nmeow";
$all =~ s/^ *\p{Lu}, \p{Ll}\n//mg;
print $all;
'
foo
meow
在cygwin上测试通过5.10.1(线程化)。
>perl -wle"$all = qq{foo\nA, x\nmeow}; $all =~ s/^ *[A-Z], [a-z]\n//mg; print $all;"
foo
meow
>perl -wle"$all = qq{foo\nA, x\nmeow}; $all =~ s/^ *\p{Lu}, \p{Ll}\n//mg; print $all;"
foo
meow
在Windows操作系统中(ActivePerl),使用5.14.0(多线程)和5.14.2(多线程)进行测试。
但是,惊奇发现!!!
>perl -wle"$all = qq{foo\nA, x\nmeow}; $all =~ s/^ *[A-Z], [a-z]\n//mg; print $all;"
foo
meow
>perl -wle"$all = qq{foo\nA, x\nmeow}; $all =~ s/^ *\p{Lu}, \p{Ll}\n//mg; print $all;"
foo
A, x
meow
在Windows (ActivePerl)上测试了5.10.1(线程),5.12.1(线程)和5.12.4(线程)。
旧版本的Perl似乎存在一个错误。它似乎已经在5.14中得到修复。该错误似乎位于优化器中(使用-Mre=debug
查看),因此可以通过“禁用”优化器来绕过该错误。
>perl -wle"$all = qq{foo\nA, x\nmeow}; $all =~ s/^ *\p{Lu}, \p{Ll}\n//mg; print $all;"
foo
A, x
meow
>perl -wle"$all = qq{foo\nA, x\nmeow}; $all =~ s/^ *\p{Lu}{1}, \p{Ll}\n//mg; print $all;"
foo
meow
$all = "foo\n A, x\nmeow";
,对于两者都有相同的结果。 - ikegami