我想从一个空哈希开始,然后在哈希中插入相同类型的哈希哈希.
#!/usr/bin/perl use strict; use warnings; my %h = {}; $h{"1"} => { a => -1,b => -1,c => [ { d => -1,e => -1,},],};
但是这给了
Useless use of hash element in void context at ./hash.pl line 8. Useless use of anonymous hash ({}) in void context at ./hash.pl line 8. Reference found where even-sized list expected at ./hash.pl line 6.
它是我想要的数据库,我可以在其中插入$h {“1”}种类的删除结构.
任何想法如何做到这一点?
解决方法
要初始化哈希,请使用%h =().
{}是一个空的匿名哈希值 reference.试试这个:
{}是一个空的匿名哈希值 reference.试试这个:
my %h = (); $h{"1"} = { a => -1,c => [{ d => -1,}],};