我正在尝试编写一个脚本,我需要处理HASH的键,我正在努力提取HASH的所有键。这是我的代码:
use strict;
use warnings;
my %HOA = (
"age" => [20 ,25],
"Name" => ["Raj" ,"Kiran"]
);
foreach my $key ( keys%HOA){
print "Key -> $HOA{$key}\n";
my @array = @{$HOA{$key}};
foreach my $val (@array){
print "val -> $val\n";
}
}
我需要将所有键存储在一个数组中。有人可以帮帮我吗?
答案 0 :(得分:1)
这将为您提供一个数组中哈希的所有数组元素。
use strict;
use warnings;
my %HOA = (
"age" => [20 ,25],
"Name" => ["Raj" ,"Kiran"]
);
my @array=map @{$HOA{$_}},keys %HOA;
foreach my $val (@array)
{
print "$val\n";
}