Perl 两个数组之间的循环
@a1 = qw(1 2 3)
@a2 = qw(1 2 3 4 5)
寻找 a1 和 a2 之间的计算结果作为 a2[0] 的值插入。例如 1+1 = 2 进入 a2[0] 作为 2,那么下一个计算将是 2+2 (a2[0] + a1[1]) 导致 a2[0] = 4,然后是 4+3 (a2[0]+a1[2]) 导致 a2[0] = 7,然后移至 a2 中的下一行并对 a1 执行相同的函数。
完成所有操作后,结果将来自 print @a2;
7 8 9 10 11
@a1 = qw(1 2 3)
@a2 = qw(1 2 3 4 5)
looking have the resultant of a calculation between a1 and a2 be inserted as the value of a2[0]. example would be 1+1 = 2 going into a2[0] as 2, then the next calculation would be 2+2 (a2[0] + a1[1]) resulting in a2[0] = 4, then 4+3 (a2[0]+a1[2]) resulting in a2[0] = 7, then move on to the next line in a2 and perform the same function against a1.
when all said and done the result would be from print @a2;
7 8 9 10 11
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,本质上您是将第一个数组中的值的总和添加到第二个数组中的每个元素。
So essentially you're adding the total of the values in the first array to each element in the second array.
使用相关列表函数:
参考:
另请参阅 Fergal的答案,在这种情况下更简单。
Using relevant list functions:
Refer:
Also refer Fergal's answer, which is simpler in this case.