是否可以强制不同的 perl 哈希键映射到相同的值?例如:
my %h = (
aaa => 'val_1',
bbb => 'val_2',
);
print "==============\n";
&dump();
$h{bbb} = \$h{aaa};
&dump();
$h{aaa} = 'new';
&dump();
sub dump{
foreach my $k ( sort keys %h ){
print "$k => $h{$k}\n";
}
print "==============\n";
}
这将打印:
==============
aaa => val_1
bbb => val_2
==============
aaa => val_1
bbb => SCALAR(0x801d48)
==============
aaa => new
bbb => SCALAR(0x801d48)
但我想要的是:
==============
aaa => val_1
bbb => val_2
==============
aaa => val_1
bbb => val_1
==============
aaa => new
bbb => new