我有一大堆哈希,我想从数组中获取一些哈希并插入新数组而不更改第一个数组。我在将哈希推送到数组时遇到问题,如何访问作为哈希的第 i 个元素。
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.
}