我有一個大的散列數組,我想從數組中獲取一些散列並插入到新數組中而不更改第一個數組。我有問題將哈希推向數組,我如何訪問哈希的第i個元素。如何訪問perl中的散列數組?
my @myarray;
$my_hash->{firstname} = "firstname";
$my_hash->{lastname} = "lastname";
$my_hash->{age} = "25";
$my_hash->{location} = "WI";
push @myarray,$my_hash;
$my_hash->{firstname} = "Lily";
$my_hash->{lastname} = "Bily";
$my_hash->{age} = "22";
$my_hash->{location} = "CA";
push @myarray,$my_hash;
$my_hash->{firstname} = "something";
$my_hash->{lastname} = "otherthing";
$my_hash->{age} = "22";
$my_hash->{location} = "NY";
push @myarray,$my_hash;
my @modifymyhash;
for (my $i=0;$i<2; $i++) {
print "No ".$i."\n";
push (@modifymyhash, $myarray[$i]);
print "".$myarray[$i]."\n"; #How do I print first ith element of array which is hash.
}
我已經使用了字符串和警告。我還初始化並定義了my_hash。我想將整個散列推入新陣列。不管怎麼說,還是要謝謝你。 – mysteriousboy 2013-03-19 21:11:32
@mysteriousboy你已經將哈希推入'@ modifymyhash'。那有什麼問題? – 2013-03-19 21:16:51