2013-04-30 44 views
2

我有以下多方面的散列變量如何分析多維散列變量在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

+0

你是什麼意思「解析變量「? – zoul 2013-04-30 06:23:20

+0

我需要獲得每個值$ billingMember {1} - > {'useremail_quota'}, $ billingMember {2} - > {'useremail_quota'} .... – 2013-04-30 06:25:25

回答

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"; 
} 

(編輯:只保留了其中一個可能會在你的情況下很有用)

+0

謝謝,其工作 – 2013-04-30 06:36:54