![](/img/trans.png)
[英]Can I use named groups in a Perl regex to get the results in a hash?
[英]Can not retrieve hash reference in perl
嗨我想在名为'chksum'的文件中保存哈希引用,并在以后需要时检索它。 但它给了我一个错误。
#!/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';
root@- [~/ftp_kasi]# perl test.pl
Not a HASH reference at test.pl line 25.
有人可以帮我解决这个问题。 提前致谢。
当你实际上只想使用hashref时,你正在存储对hashref的引用,所以替换
store \$files, 'checksum';
同
store $files, 'checksum';
$ref
是空的,因为||=
运算符不会按照您的想法执行。 怎么样使用||
代替?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.