您好,我試圖保存一個名爲'chksum'的文件中的哈希引用,並在需要時再檢索它。但它給了我一個錯誤。無法在perl中檢索哈希引用
Test.pl
#!/usr/local/cpanel/3rdparty/bin/perl
use Storable;
use File::Find qw(find);
use Digest::MD5 qw(md5_base64);
use Data::Dumper;
#=head
######################
#Collect checksum #
######################
my $files = {};
$files_ref = retrieve('checksum');
find(sub {
my $file = $File::Find::name;
return if ! length($file);
my ($size, $mtime) = (stat $_)[7, 9];
open (FILE, $file);
$chksum = md5_base64(<FILE>);
$files->{$file} = {
local_is_dir => (-d _ ? 1 : 0),
local_size => $size,
local_mtime => $mtime,
chksum => $chksum,
};
#$ref = $files->{$file} || = {};
my $ref = $files_ref->{$file} ||= {};
if ($chksum != $ref->{chksum}) {print $file;}
}, '/root/ftp_kasi/');
#print Dumper(\$files);
store \$files, 'checksum';
輸出
[email protected] [~/ftp_kasi]# perl test.pl
Not a HASH reference at test.pl line 25.
有人可以幫我出這一點。提前致謝。
'打印自卸車$ files_ref,$文件;'分配之前,檢查。也考慮使用嚴格和警告=> http://stackoverflow.com/questions/8023959/why-use-strict-and-warnings –
謝謝我使用嚴格和警告,但沒有其他錯誤消息。 「不在test.pl第25行的HASH參考」出現在作業行中。因此,打印Dumper $ ref不會產生任何結果。 –
'print Dumper $ files_ref,$ file;'但在$ ref assigment之前。 '$ files_ref'不像它看起來那樣是hashref。 –