Find key name in hash with only one key?

后端 未结 7 537
鱼传尺愫
鱼传尺愫 2021-02-03 22:37

If I have a hash

my %h = (
    secret => 1;
);

and I know that is only is one key in the hash, but I don\'t know what it is called.

7条回答
  •  一个人的身影
    2021-02-03 23:07

    I do not believe it is necessary to use the keys function.

    my ($key) = %h;
    

    or

    my $key = (%h)[0];
    

    The hash inside the parens will be expanded to a list, then we can simply take the first element of that list, which is the key.

提交回复
热议问题