对于perl中数组中的每个对象
我试图在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
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',
}
);
然后剩下的代码就可以正常工作了。是的,注意到了,真烦人!谢谢它发生了!一双新鲜的眼睛通常会有帮助,我很高兴我的眼睛能帮上忙。是的,我看得很清楚,真烦人!谢谢它发生了!一双新鲜的眼睛通常会有帮助,我很高兴我的眼睛有帮助。