如何将值压入数组的Perl哈希? [英] How do I push a value onto a Perl hash of arrays?

查看:189
本文介绍了如何将值压入数组的Perl哈希?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

%TEST ; 

... 
for  {
   sub atest
   }
 sub atest {
 ...
    push $TEST { TEST1 }[0] = "some value " 
}

如何在不了解索引的情况下将值推入数组的哈希中?

How do I push values into a hash of arrays without knowing anything about index?

我该如何实现?

推荐答案

这将通过"TEST1"键将值添加到存储在哈希中的数组的末尾.

This will add value to the end of array stored in hash by "TEST1" key.

push( @{ $TEST { TEST1 } }, "some value "); 

我已使用@{...}取消引用数组引用.然后,Perl会自动创建内部数组引用.

I've used @{...} to dereference array reference. Perl creates inner array reference automatically then needed.

这篇关于如何将值压入数组的Perl哈希?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆