新手问题 二维哈希如何遍历?

kingwmj · April 07, 2013 · Last by kingwmj replied at April 08, 2013 · 9165 hits

二维哈希如何遍历?请教一下。在网上没有找到。

神马叫二维哈希哈。。

有没有像 perl 这样的?我刚从 perl 转过来,不懂递归啊. use strict; use warnings; my %hash=(a=>{1=>10,2=>20},b=>{3=>30,4=>40}); foreach my $key1 (keys(%hash)){
print("\$hash{$key1} has keys:".join(',',keys(%{$hash{$key1}})),"\n"); }

#3 楼 @kingwmj

hash = {'a'=>{1=>10,2=>20},'b'=>{3=>30,4=>40}}
hash.each{|key1, hash1|
  print "hash #{key1} has keys:", hash1.keys.join(','), "\n"
}

谢谢楼上的几位,更谢谢 luikore,你说的我看明白了,比 perl 的好用。

You need to Sign in before reply, if you don't have an account, please Sign up first.