如何取消引用已传递给子例程的Perl哈希引用? [英] How do I dereference a Perl hash reference that's been passed to a subroutine?
问题描述
我仍然试图理清我的散列解引用。我目前的问题是我现在将一个hashref传递给一个sub,并且我想在该sub中解引用它。但是我没有找到正确的方法/语法来做到这一点。在sub中,我想迭代散列键,但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.
我想这样做:
sub foo {
%parms = @_;
foreach $keys (key %parms) { # do something };
}
但传入的是散列,而不是散列。
but with a hashref being passed in instead of a hash.
欢迎任何指针(不是双关)。
Any pointers (pun not intended) are welcome.
谢谢。
推荐答案
目前我没有真正测试代码,但写意你会想要做这样的事情:
I havn't actually tested the code at this time, but writing freehand you'll want to do something like this:
sub foo {
$parms = shift;
foreach my $key (keys %$parms) { # do something };
}
这篇关于如何取消引用已传递给子例程的Perl哈希引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!