小编arj*_*ini的帖子

迭代A Perl Hash会打印出一个内存地址

以下子例程用于迭代节点数组(每个节点的哈希值都有一个大陆)并返回所有国家/地区的列表:

sub getContinentsServed{
    my $self = shift;
    my $temp = $self->{cityListRef};
    my %hash = {};
    my $h_ref = \%hash;
    foreach my $cont (@{$temp}){
        $h_ref->{$cont->{continent}} = '1';
    }
    print "Continents Served: ";
    foreach my $coord (keys %hash){
        print $coord;
        print " , ";
    }
} 
Run Code Online (Sandbox Code Playgroud)

我很确定这包含所有正确的数据,但是当我尝试打印这些值时,我得到了这个结果:

Continents Served: Australia Europe North America South America Asia Africa HASH(0x100949a70) 
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么我会得到最后一个元素HASH(0x1009...).我宁愿这不会出现,但我所做的只是迭代键,所以我不确定为什么或如何那样.

memory perl hash hashmap

1
推荐指数
1
解决办法
1229
查看次数

标签 统计

hash ×1

hashmap ×1

memory ×1

perl ×1