可能重复:
当 perl 中的键相同时连接哈希值
我想在哈希中存储一个键的多个值。例如:
Input:
SMP00001 HMDB00641
SMP00001 HMDB00051
SMP00001 HMDB00052
SMP00003 HMDB00051
SMP00003 HMDB00517
SMP00004 HMDB00243
Output:
SMP00001: HMDB00641,HMDB00051,HMDB00052
SMP00003: HMDB00051,HMDB00517
SMP00004: HMDB00243
这是我写的代码:
push(@{$hash{$smp_id}},$HMDB_id);
当我在哈希中打印内容时,输出是:
SMP00001 => ARRAY(0x161da40)
SMP00003 => ARRAY(0x11be28)
SMP00004 => ARRAY(0x1265c8)