在eval中使用正则表达式之后如何得到($`,$&,$')的值?

在eval中使用正则表达式之后如何得到($`,$&,$')的值?

代码如下
#!/usr/bin/perl -w

use strict;
use warnings;
use diagnostics;

my $RegEx =  'm/AAA/';
my $Line = "CCCAAABBB";
eval '$Line =~ ' . $RegEx;
print "\$`: $`\n";
print "\$&: $&\n";
print "\$': $'\n";


报错是
Use of uninitialized value $` in concatenation (.) or string at EvalTest.pl
        line 9 (#1)
    (W uninitialized) An undefined value was used as if it were already
    defined.  It was interpreted as a "" or a 0, but maybe it was a mistake.
    To suppress this warning assign a defined value to your variables.

是不是eval把正则表达式的匹配放在单独的上下文中,导致外面拿不到($`,$&,$')的值?
有什么办法可以解决吗?

本意是想从文件读入正则表达式用于处理其他文本。


忘大侠不吝赐教!



感谢black_fired的回复!才学perl,很多不懂,也看不很懂你的回复。
难道local $'了会对eval中的$'有影响吗?

因为不知道在回复中怎么贴代码,所以修改本帖。
我是这么解决的
#!/usr/bin/perl -w

use strict;
use warnings;
use diagnostics;

my $RegEx =  's/AAA/KKK/';
my $Line = "CCCAAABBB";
my $Value = 'init';
my $Program = '$Line =~ ' . $RegEx . ';';
$Program .= '$Value = $`;';
#$Program .= 'print "\$`: $`\n";';

print "$Value\n";
print "$Line\n";
eval $Program;
print "$Value\n";
print "$Line\n";



反正把变量赋值也放到eval中去执行就可以了。

s/忘/望/
perdoc上面的例子:

    local $_ = 'abcdefghi';
    /def/;
    print "$`&'\n";          # prints abc:def:ghi
$`, $&, $':
"This variable is read-only and dynamically scoped to the current BLOCK."
eval 的代码是当作一个块看待的,所以任何在 eval 里定义的局部范围的变量都只能持续到 eval 结束