我在Perl中编写了以下函数:
sub save
{
my($dir,$name,%hash) = @_;
my $prop = Config::Properties->new();
my $file = $dir."/.".$name;
open my $fh, ">", $file or return 0;
foreach my $p (keys(%hash))
{
$properties->setProperty($p => $hash{$p});
}
$properties->store($fh);
close ($fh);
return 1;
}
sub read
{
my ($dir,$name) = @_;
my ($user, $start_time, $workdir, $rules_file);
my $file = $dir."/.".$name;
open my $fh, "<", $file or return 0;
my $prop = Config::Properties->new();
$properties->load($fh);
my %hash = $properties->properties;
close ($fh);
return %hash;
}
为了将配置哈希保存到文件中,然后读取它。但是,如果哈希值之一是数组,它将仅显示该数组的地址。为了使代码支持数组读写,我应该对代码做什么更改?