我有一个哈希:
$VAR1 = {
'x' => {
'Mathematics' => 82,
'Art' => 99,
'Literature' => 88
},
'y' => {
'Mathematics' => 97,
'Literature' => 67
}
.......
};
我需要在数组中获取x, y
等(目前我不知道x和y的值)
例如
@arr = (x,y, z..);
答案 0 :(得分:3)
只需使用keys
即可。如果哈希实际上是哈希引用,则首先取消引用它:
my @keys1 = keys %hash;
my @keys2 = keys %$hash_ref;