如何直接将SOLE哈希键分配给perl中的标量

klo*_*oot 0 syntax perl hash scalar

是否可以将唯一的现有哈希键直接分配给标量?

例如,这两个陈述可以组合成一个吗?

@the_keys = keys %the_hash;       # a hash with a single key
$the_sole_key = shift @the_keys;
Run Code Online (Sandbox Code Playgroud)

%theha中存在SINGLE键已在前面的代码中得到验证.

提前致谢!

ike*_*ami 5

my ($key) = keys(%hash);
Run Code Online (Sandbox Code Playgroud)

要么

my $key = ( keys(%hash) )[0];
Run Code Online (Sandbox Code Playgroud)