如何在Perl中找出散列引用的位置?
$hoh_ref
不是哈希引用(或任何类型的引用)。
my $hoh_ref = \%hoh;
$hoh_ref = $hoh_ref->{flintstones};
$hoh_ref = $hoh_ref->{husband};
与相同
my $hoh_ref = "fred";
也就是说它创建了标量
$HOH参考
并将其值设置为字符串
fred
. 在这两种情况下,两者之间绝对没有关联(名称错误)
$HOH参考
和
%hoh
但是,hoh的一个值恰好等于
$HOH参考
.
+- %hoh -----------------------+ +- Anon hash ------------------+
| +-----------+ | +---->| +-----------+ |
| flintstones: | Ref ----------+ | husband: | fred | |
| +-----------+ | | +-----------+ |
| jetsons: | Ref ------------+ | pal: | barney | |
| +-----------+ | | | +-----------+ |
| simpsons: | Ref --------+ | +------------------------------+
| +-----------+ | | |
+------------------------------+ | | +- Anon hash ------------------+
| +-->| +-----------+ |
+- $hoh_ref -------------------+ | | husband: | george | |
| fred | | | +-----------+ |
+------------------------------+ | | wife: | jane | |
| | +-----------+ |
| | his boy: | elroy | |
| | +-----------+ |
| +------------------------------+
|
| +- Anon hash ------------------+
+------>| +-----------+ |
| husband: | homer | |
| +-----------+ |
| wife: | marge | |
| +-----------+ |
| kid: | bart | |
| +-----------+ |
+------------------------------+
所以,充其量,您可以迭代
%HOH
查找等于
$HOH参考
.
我不想循环遍历原始哈希并找到值的位置
太糟糕了。