本文介绍了我怎样才能总结数组元素智能在Perl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
@arr1 = ( 1, 0, 0, 0, 1 );
@arr2 = ( 1, 1, 0, 1, 1 );
我要总结两个阵列的项目获得新的像
I want to sum items of both arrays to get new one like
( 2, 1, 0, 1, 2 );
我可以不用通过数组循环?
Can I do it without looping through arrays?
推荐答案
为Perl 5:
use List::MoreUtils 'pairwise';
@sum = pairwise { $a + $b } @arr1, @arr2;
这篇关于我怎样才能总结数组元素智能在Perl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!