Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对于perl中数组中的每个对象_Perl_Loops_For Loop - Fatal编程技术网

对于perl中数组中的每个对象

对于perl中数组中的每个对象,perl,loops,for-loop,Perl,Loops,For Loop,我试图在Perl中循环遍历数组中的每个对象,我认为我犯了一个明显的错误 my @members_array = [ { id => 1234, email => 'first@example.com', }, { id => 4321, email => 'second@example.com', } ]; use Data::Dumper; for my $member

我试图在Perl中循环遍历数组中的每个对象,我认为我犯了一个明显的错误

my @members_array = [
    {
        id    => 1234,
        email => 'first@example.com',
    }, {
        id    => 4321,
        email => 'second@example.com',
    }
];

use Data::Dumper;
for my $member ( @members_array ) {
    print Dumper( $member );
}
第一次迭代的预期输出

{
    id    => 1234,
    email => 'first@example.com',
}
[{
    'email' => 'first@example.com',
    'id' => 1234
 }, {
    'email' => 'second@example.com',
    'id' => 4321
}];
第一次迭代的实际输出

{
    id    => 1234,
    email => 'first@example.com',
}
[{
    'email' => 'first@example.com',
    'id' => 1234
 }, {
    'email' => 'second@example.com',
    'id' => 4321
}];

如何循环数组中的这些元素?谢谢

[…]
用于创建数组引用;您需要使用
(…)
来创建数组:

my @members_array = (
    {
        id    => 1234,
        email => 'first@example.com',
    }, {
        id    => 4321,
        email => 'second@example.com',
    }
);

然后剩下的代码就可以正常工作了。

[…]
用于创建数组引用;您需要使用
(…)
来创建数组:

my @members_array = (
    {
        id    => 1234,
        email => 'first@example.com',
    }, {
        id    => 4321,
        email => 'second@example.com',
    }
);

然后剩下的代码就可以正常工作了。

是的,注意到了,真烦人!谢谢它发生了!一双新鲜的眼睛通常会有帮助,我很高兴我的眼睛能帮上忙。是的,我看得很清楚,真烦人!谢谢它发生了!一双新鲜的眼睛通常会有帮助,我很高兴我的眼睛有帮助。