如何取消引用已传递给子例程的 Perl 哈希引用?
我仍在尝试解决我的哈希取消引用问题。我当前的问题是我现在将 hashref 传递给子组件,并且我想在该子组件中取消引用它。但我没有找到正确的方法/语法来做到这一点。在 sub 中,我想迭代哈希键,但 hashref 的语法与哈希不同,我知道该怎么做。
所以我想要的是这样做:
sub foo {
%parms = @_;
foreach $keys (key %parms) { # do something };
}
但传入的是 hashref 而不是哈希。
I'm still trying to sort out my hash dereferencing. My current problem is I am now passing a hashref to a sub, and I want to dereference it within that sub. But I'm not finding the correct method/syntax to do it. Within the sub, I want to iterate the hash keys, but the syntax for a hashref is not the same as a hash, which I know how to do.
So what I want is to do this:
sub foo {
%parms = @_;
foreach $keys (key %parms) { # do something };
}
but with a hashref being passed in instead of a hash.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我目前还没有实际测试代码,但是徒手编写你会想要做这样的事情:
I havn't actually tested the code at this time, but writing freehand you'll want to do something like this:
以下是取消引用传递给子节点的哈希引用的一种方法:
另请参阅引用快速参考和 perlreftut
Here is one way to dereference a hash ref passed to a sub:
See also References quick reference and perlreftut
这里还有一个关于引用的很好的介绍。
Also a good intro about references is here.
取消引用原始引用,但将其用作另一个/其副本,这也是很常见或更常见的。
Dereference the original reference, but use it as another one / its copy, what is also very common or more common.