相关疑难解决方法(0)

如何在Perl中迭代哈希(哈希)?

我有哈希,其中键的值是其他哈希.

例: {'key' => {'key2' => {'key3' => 'value'}}}

我怎样才能遍历这个结构?

perl hash perl-data-structures

16
推荐指数
5
解决办法
4万
查看次数

如何在perl中访问哈希数组?

我有一大堆哈希,我想从数组中获取一些哈希并插入新数组而不更改第一个数组.我有问题将哈希推送到数组,如何访问作为哈希的第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.
 }
Run Code Online (Sandbox Code Playgroud)

arrays perl hash push

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

hash ×2

perl ×2

arrays ×1

perl-data-structures ×1

push ×1