如何在Perl中解析多维哈希变量

时间:2013-04-30 06:21:36

标签: perl

我有以下多维哈希变量

my %billingMember ;
$billingMember{1}->{'useremail_quota'} = 10;
$billingMember{1}->{'useremail_blockedquota'} = 5;

$billingMember{2}->{'useremail_quota'} = 10;
$billingMember{2}->{'useremail_blockedquota'} = 5;

如何解析变量%billingMember?

即我需要获得每个值

$ billingMember {1} - > { 'useremail_quota'},

$ billingMember {1} - > {'useremail_blockedquota'},

$ billingMember {2} - > {'useremail_quota'},....

这里1& 2只是例如,它将动态

所以我认为,我们需要使用 foreach

1 个答案:

答案 0 :(得分:2)

取自http://perldoc.perl.org/perldsc.html#HASHES-OF-HASHES的一些样本:

 foreach $family ( keys %HoH ) {
     print "$family: { ";
     for $role ( keys %{ $HoH{$family} } ) {
         print "$role=$HoH{$family}{$role} ";
     }
     print "}\n";
 }

(编辑:只保留可能对您的情况有用的那个)