2014-09-11 85 views
-2

我有一個散列數組,我想改變鍵值,我該怎麼做?如果散列值在數組中,如何訪問散列值? PERL

my @AoH =(); 
for (my $i=0; $i < scalar @fileRows; $i++) { 
    my %fields =(); 
    @fields{@wordsAll} = (1) x @wordsAll; #key names are from array 
    push @AoH, {%fields}; 
} 
+1

你能更清楚轉換爲哈希散列運算每個數組索引..散列參考,請? – ikegami 2014-09-11 12:58:53

+0

btw,'push @AoH,{%fields};'創建一個新的哈希值。你想'推@AoH,\%字段;' – ikegami 2014-09-11 12:59:35

+0

你的目標是什麼是完全不清楚的。請編輯該問題以提供更多詳細信息,解釋您的設置和問題。 – Miller 2014-09-11 17:58:52

回答

1

使用foreach,並得到以你需要將它與%{}

my @AoH =(); 

    foreach my $hash (@AoH){ 
     #edit the hash here 
     $hash->{'key'} = 'value'; 
     my @keys = keys %$hash; 
     my @values = values %$hash; 
    }