TLP*_*TLP 23
是的.使用反斜杠创建对数组的引用:
$hash{key} = \@array;
Run Code Online (Sandbox Code Playgroud)
请注意,这将链接到实际数组,因此如果您执行更改,例如:
$array[0] = "foo";
Run Code Online (Sandbox Code Playgroud)
这也意味着$hash{key}[0]设置为"foo".
如果这不是您想要的,您可以使用匿名数组引用复制值[ ... ]:
$hash{key} = [ @array ];
Run Code Online (Sandbox Code Playgroud)
而且,您不必通过数组来执行此操作.您可以直接分配:
$hash{key} = [ qw(foo bar baz) ];
Run Code Online (Sandbox Code Playgroud)
阅读更多关于在perldoc perlref中进行引用的信息
yst*_*sth 10
是.有关访问此类数据结构的一些基本规则,请参阅http://perlmonks.org/?node=References+quick+reference,但要创建它,只需执行以下操作之一:
%hash = ( 'somekey' => \@arrayvalue );
$hash{'somekey'} = \@arrayvalue;
%hash = ( 'somekey' => [ ... ] );
Run Code Online (Sandbox Code Playgroud)