我有一个perl脚本和一个.config文件,并且希望在配置文件中存储一些散列作为其值,然后从我的perl脚本动态更改它们。在perl配置文件中设置变量eval
配置文件:
$hash{"hello"} = ["$blah", "$blah2"];
我的perl脚本:
if (-e ".config")
{
$blah = "hello";
$blah2 = "world!";
eval ('require(".config")');
$val1 = $hash{"hello"}[0];
$val2 = $hash{"hello"}[1];
print "$val1 $val2\n";
# Now I want to CHANGE blah and blah2
$blah = "world!";
$blah2 = "hello";
$val1 = $hash{"hello"}[0];
$val2 = $hash{"hello"}[1];
print "$val1 $val2\n";
}
但两者的打印显示hello world!
好像变化没有发生..我缺少的东西?
谢谢。
这个的任何例子?新的perl ..谢谢! – Travv92
另请参阅:http://stackoverflow.com/questions/7506782/initializing-perl-variables-using-eval –