如何访问二级哈希表元素
url_hash为第一级hash,${$url_hash{$key1}}{"query"}为第二级hash,现在想访问其中的元素,编写代码如下,但是打#**的print语句不能得到正确的结果,求指教。
while(($key2, $value2) = each %{${$url_hash{$key1}}{"query"}}){ print "$value2\t"; print ${$url_hash{$mainurl}{"query"}}{$key2}; print "\n";}
print ${$url_hash{my}{query}}{x}, "\n";
[解决办法]
#!/usr/bin/env perl%url_hash = ( my => { query => { x => 1, y => 2, z => 3, } }, me => { query => { x => 4, y => 5, z => 6, } },);$key1 = 'my';while (($k, $v) = each %{${$url_hash{$key1}}{query}}) { print "$v\t"; print ${$url_hash{my}{query}}{$k}, "\n";}