我一直在试图找出今晚的方式。我已将它搜索到死亡,并且没有任何示例或我的黑客实例正在完成。看来这应该很容易,但我无法得到它。下面是代码:使用Data :: Dumper的Perl持久数据存储
#!/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";
,这里是我的输出:我读说,TEST003输出应该等同于TEST001输出,这正是我想达到
$VAR1 = {
'key2' => 'value2',
'key1' => 'value1',
'key3' => 'value3',
'key' => 'value'
};
TEST001
$VAR1 = {};
TEST002
$VAR1 = {};
TEST003
一切。
我在这里错过了什么?我应该以不同的方式“做”,还是应该“评估”?如果是,如何?
感谢您的任何帮助...
谢谢,这就是它! – stephenmm 2010-03-26 04:38:14