How can I sum arrays element-wise in Perl?

前端 未结 9 519
孤城傲影
孤城傲影 2020-12-15 07:53

I have two arrays:

@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

<         


        
9条回答
  •  温柔的废话
    2020-12-15 08:32

    what's wrong with looping over arrays? that's the fundamentals.

    @arr1 = ( 1, 0, 0, 0, 1 );
    @arr2 = ( 1, 1, 0, 1, 1 );
    for ($i=0;$i

提交回复
热议问题