Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何将 Perl hashref 解压成多个命名的标量变量?
我已经看到它完成了,但似乎无法使其工作。
假设$hashref给定的和$arg1to的定义$arg3,这是我的尝试:
$hashref
$arg1
$arg3
my $hashref = { arg1 => 'val1', arg2 => 'val2', arg3 => 'val3',}; my ($arg1,$arg2,$arg3) = @{%$hashref}[qw(arg1 arg2 arg3)];
你需要这个
my ($arg1,$arg2,$arg3) = @{$hashref}{qw(arg1 arg2 arg3)};
这是针对哈希引用的哈希切片