Hash不会在Perl中打印

use*_*545 1 perl hash

我有一个哈希:

while( my( $key, $value ) = each %sorted_features ){
  print "$key: $value\n";
}
Run Code Online (Sandbox Code Playgroud)

但我无法获得正确的价值$value.它给了我:

intron: ARRAY(0x3430440)
source: ARRAY(0x34303b0)
exon: ARRAY(0x34303f8)
sig_peptide: ARRAY(0x33f0a48)
mat_peptide: ARRAY(0x3430008)
Run Code Online (Sandbox Code Playgroud)

为什么?

TLP*_*TLP 10

您的值是数组引用.你需要做点什么

while( my( $key, $value ) = each %sorted_features ) {
  print "$key: @$value\n";
}
Run Code Online (Sandbox Code Playgroud)

换句话说,取消引用参考.如果您不确定数据是什么样的,最好使用该Data::Dumper模块:

use Data::Dumper;
print Dumper \%sorted_features;
Run Code Online (Sandbox Code Playgroud)

你会看到类似的东西:

$VAR1 = {
          'intron' => [
                        1,
                        2,
                        3
                      ]
        };
Run Code Online (Sandbox Code Playgroud)

Where {表示哈希引用的开始和[数组引用.