如果在eval中发生正则表达式匹配,则在外部环境中看不到与捕获相关的变量($ 1等)的更改.这是一个错误吗?
perlop和perlre似乎没有提到任何这样的限制.
例如:
use strict; use warnings;
$_ = "hello";
eval '/(.*)/';
print "GOT: $1\n";
Run Code Online (Sandbox Code Playgroud)
得到:
Use of uninitialized value $1 in concatenation (.) or string at -e line 1.
GOT:
Run Code Online (Sandbox Code Playgroud)
更简洁的演示是:
perl -we '$_="foo"; eval q(/(.*)/;) ; print "GOT:$1\n";'
Run Code Online (Sandbox Code Playgroud)