没有必要将所有数据序列化以获得(可能是巨大的)散列键.而是采用数据结构的校验和并将其用于密钥.将原始密钥存储为值的一部分.
这是使用perl5i进行深度校验和的示例.
use perl5i::2; $hash{@stuff->mo->checksum} = { key => \@stuff, value => 'value' }; my $value = $hash{@stuff->mo->checksum}{value}; my $key = $hash{@stuff->mo->checksum}{key};
你可以将它包装在一个小类中,以使它更方便.
sub get { my $self = shift; my $key = shift; return $self->{$key->mo->checksum}{value}; } sub set { my $self = shift; my($key, $val) = @_; $self->{$key->mo->checksum} = $val; return; } sub each { my $self = shift; my $code = shift; my $val; while( (undef, $val) = each %$self ) { $code->($val->{key}, $val->{value}); } return; } $obj->set(\@stuff, "value"); my $value = $obj->get(\@stuff); $obj->each( func($key, $val) { say "$key -> $val\n"; }