http://www.perlmonks.org?node_id=1001535


in reply to @array elements multiplication with another array elements.

use warnings; use strict; my @array1 = (3,4,6,5,8); my @array2 = (2,2,4,5,1); my $num = scalar @array1; my @answers; for (my $x = 0; $x < $num; $x++) { push(@answers, $array1[$x]*$array2[$x]); }

Replies are listed 'Best First'.
Re^2: @array elements multiplication with another array elements.
by 2teez (Vicar) on Oct 30, 2012 at 18:50 UTC

    Or use a for ( or foreach ) loop like so:

    my @answers; for my $x ( 0 .. $#array1 ) { push @answers, $array1[$x] * $array2[$x]; }

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me