今晚我一直在努力解决这个问题。我已经用谷歌搜索了它,但没有一个例子或我对这些例子的破解完成它。看起来这应该很容易,但我就是无法理解。这是代码:
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my $complex_variable = {};
my $MEMORY = "$ENV{HOME}/data/memory-file";
$complex_variable->{ 'key' } = 'value';
$complex_variable->{ 'key1' } = 'value1';
$complex_variable->{ 'key2' } = 'value2';
$complex_variable->{ 'key3' } = 'value3';
print Dumper($complex_variable)."TEST001\n";
open M, ">$MEMORY" or die;
print M Data::Dumper->Dump([$complex_variable], ['$complex_variable']);
close M;
$complex_variable = {};
print Dumper($complex_variable)."TEST002\n";
# Then later to restore the value, it's simply:
do $MEMORY;
#eval $MEMORY;
print Dumper($complex_variable)."TEST003\n";
这是我的输出:
$VAR1 = {
'key2' => 'value2',
'key1' => 'value1',
'key3' => 'value3',
'key' => 'value'
};
TEST001
$VAR1 = {};
TEST002
$VAR1 = {};
TEST003
我读到的所有内容都表明 TEST003 输出看起来应该与 TEST001 输出相同,这正是我想要实现的。
我在这里想念什么?我应该以不同的方式“做”,还是应该“评估”,如果是的话怎么做?
谢谢你的帮助...