在Perl中切片嵌套哈希

Ame*_*ina 5 perl hash slice

假设我有一个哈希,我可以索引为:

$hash{$document}{$word}
Run Code Online (Sandbox Code Playgroud)

从我在网上看到的内容(虽然我在perlreftut,perldscperllol上找不到这个),如果我@在哈希上使用前缀来指示我希望哈希返回列表,我可以使用列表切片哈希.但是,如果我尝试使用列表切片我的哈希@list:

@%hash{$document}{@list}
Run Code Online (Sandbox Code Playgroud)

我收到了几个"Scalar values ... better written" 错误.

如何在Perl中删除嵌套哈希?

TLP*_*TLP 7

你的哈希的sigill必须是@这样的:

@{$hash{$document}}{@list}
Run Code Online (Sandbox Code Playgroud)

假设@list包含有效密钥,%hash它将返回相应的值,或者undef如果密钥不存在.

这基于散列片的一般规则:

%foo = ( a => 1, b => 2, c => 3 );
print @foo{'a','b'};               # prints 12
%bar = ( foo => \%foo );           # foo is now a reference in %bar
print @{ $bar{foo} }{'a','b'};     # prints 12, same data as before
Run Code Online (Sandbox Code Playgroud)