我一直在試圖找出今晚的方式。我已將它搜索到死亡,並且沒有任何示例或我的黑客實例正在完成。看來這應該很容易,但我無法得到它。下面是代碼:使用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