Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Summing the elements of multiple arrays into a new array

by CharlesClarkson (Curate)
on Nov 01, 2001 at 03:59 UTC ( #122458=note: print w/ replies, xml ) Need Help??


in reply to Summing the elements of multiple arrays into a new array

You could just flatten out the loop you have:

my @foo = my @bar = qw(1 2 3 4); my @foobar; $foobar[$_] = $foo[$_] + $bar[$_] for 0 .. $#foo;

Now it will handle any two equally sized arrays and is fairly readable.


HTH,
Charles K. Clarkson


Comment on Re: Summing the elements of multiple arrays into a new array
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://122458]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2015-07-05 09:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (61 votes), past polls