如果试图使用perl hash
. 中没有未定义的值或新行__DATA__
(也尝试从文件中提供相同的输入)。但是,在使用数据转储器或传统方式打印时,我得到了一个''
作为键和undef
它的值。为什么会这样?我错过了一些明显的东西吗?
程序:
use strict;
use Data::Dumper;
my %i_hash = undef;
my %p_hash = undef;
while (<DATA>) {
chomp;
my @line = split(/\h+/);
$i_hash{ $line[0] } = $line[1]; # Interactions Hash
$p_hash{ $line[0] } = $line[2]; # PMIDs Hash
}
print Dumper( \%i_hash, \%p_hash );
__DATA__
AAA BBB PMID_1
BBB AAA PMID_2
CCC AAA PMID_3
DDD CCC PMID_4
EEE FFF PMID_1
FFF GGG PMID_6
输出:
$VAR1 = {
'' => undef,
'FFF' => 'GGG',
'CCC' => 'AAA',
'BBB' => 'AAA',
'EEE' => 'FFF',
'DDD' => 'CCC',
'AAA' => 'BBB'
};
$VAR2 = {
'' => undef,
'FFF' => 'PMID_6',
'CCC' => 'PMID_3',
'BBB' => 'PMID_2',
'EEE' => 'PMID_1',
'DDD' => 'PMID_4',
'AAA' => 'PMID_1'
};