perl5 中损坏的正则表达式捕获变量的非破坏性替代?

Non-destructive substitute on regex capture variables broken in perl5?

我注意到了一个我觉得可疑的行为。已在 perl 5.18 和 perl 5.22 上得到肯定验证。

下面用简化的一行来说明。

$ echo -e "A B C D\n# E F G" | perl -wnE 'm{(.) (.) (.) (.)}; say(,,,); say "HELLO  " . ( =~ s/\w/###/r) ."   "'
ABCD
Use of uninitialized value  in concatenation (.) or string at -e line 1, <> line 1.
Use of uninitialized value  in concatenation (.) or string at -e line 1, <> line 1.
Use of uninitialized value  in concatenation (.) or string at -e line 1, <> line 1.
HELLO A ###   
#EFG
HELLO # # E F G

显然,对任何与捕获相关的变量调用非破坏性替换会取消定义或以某种方式阻止访问任何先前定义的与捕获相关的变量。使用命名捕获和 %+ 哈希时也是如此。

这对我来说似乎是一个错误,但我不知道我是否遗漏了什么。

提前致谢。

perlvar:

Perl sets these variables when it has a successful match

因此,任何匹配成功都会清除值,与匹配变量本身是否匹配无关。