下午修改一段Perl代码的时候,遇到了一个深度拷贝的问题。废话少说,上代码:
my ($rc, $refdata) = db_query($sql_text, "hashref");
unless ($rc) {
return ($rc, $refdata);
}
my @arrayhash = ();
foreach my $ref (@$refdata) {
# 这里$ref->{host_ip}的值为"10.136.142.205,127.0.0.1"
if (defined($ref->{"is_logserver_log"})
&& $ref->{"is_logserver_log"} eq "y"
&& defined($ref->{"host_ip"}))
{
foreach my $host (split(/,/, $ref->{"host_ip"})) {
$ref->{"host_ip"} = $host;
if ($ref->{"host_ip"} eq "127.0.0.1") {
write_log("1 " . Dumper($ref) . "\n")
}
push @arrayhash, $ref;
}
}
else {
push @arrayhash, $ref;
}
}
foreach my $tmp (@arrayhash) {
if ($tmp->{"host_ip"} eq "127.0.0.1") {