Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: @array elements multiplication with another array elements.

by Pizentios (Scribe)
on Oct 30, 2012 at 18:37 UTC ( #1001535=note: print w/replies, xml ) Need Help??


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 (Priest) 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1001535]
help
Chatterbox?
[choroba]: Didn't you forget to add a title? Did you include links to the post?
[LanX]: choroba IIRC these errors are indicated
[1nickt]: Missing title suppresses the submit button, I think.
[1nickt]: Petroza to answer your question, no, no special permission is needed to post a question.
[LanX]: did you spam before? :)
LanX has to go/
[ambrus]: I hope we didn't mess up the spam filter rules again.
[ambrus]: Our spam filter rules disallow links to certain domains, and some suspicious pharses that have appeared in previous spam advertising cheap online whatevers.
[LanX]: some servers were lagging today, so I suppose the root cause
[LanX]: ambrus no recent patches

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2017-10-17 15:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (233 votes). Check out past polls.

    Notices?