数组 – 如何在哈希中插入哈希哈希值?

前端之家收集整理的这篇文章主要介绍了数组 – 如何在哈希中插入哈希哈希值?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想从一个空哈希开始,然后在哈希中插入相同类型的哈希哈希.

#!/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.试试这个:

my %h = ();

$h{"1"} = {
    a => -1,c => [{
        d => -1,}],};

猜你在找的Perl相关文章