PERL:使用来自匿名哈希的数据
我正在添加到其他开发人员代码中,我们都是Perl的新手,我正在尝试列出IPS并通过WHOIS运行它。我不确定如何访问匿名哈希中的数据,如何使用它? 他告诉我数据存储在其中。这是我唯一可以提及哈希的实例:
## Instantiate a reference to an anonymous hash (key value pair)
my $addr = {};
I am adding on to another developers code, we are both new to perl I am trying to take a list of IPs and run it through whois. I am unsure how to access the data in the anonymous hash, how do I use it?
He told me the data was stored inside one. This is the only instance I could find mentioning a hash:
## Instantiate a reference to an anonymous hash (key value pair)
my $addr = {};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
匿名哈希是
{}
part。它返回一个可以存储在标量变量中的引用,例如在您的示例中:要查看结构,您可以使用
data :: Dumper
:内容:
您使用箭头操作员访问哈希键:
它可能向您显示类似的 您将如何访问常规哈希,但是介于两者之间的箭头操作员。
您可以通过将sigil放在前面放置参考
The anonymous hash is the
{}
part. It returns a reference which can be stored in a scalar variable, like in your example:To see the structure, you can print it with
Data::Dumper
:It might show you something like:
You access the hash keys using the arrow operator:
Like how you would access a regular hash, but with the arrow operator in between.
You can dereference the reference by putting a hash sigil in front
这是一个匿名哈希:
如果要访问单个值:
如果要更新单个值:
如果要添加新的键/值对:
也可以使用所有标准哈希功能(例如
keys()
)。您只需要“尊重”您的哈希参考 - 这意味着将'%'放在面前。因此,例如,打印所有密钥/值对:
Here is an anonymous hash:
If you want to access an individual value:
If you want to update an individual value:
If you want to add a new key/value pair:
You can also use all of the standard hash functions (e.g.
keys()
). You just need to "deference" your hash reference - which means putting a '%' in front of it.So, for example, to print all the key/value pairs: