Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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 meditating upon the Monastery: (7)
As of 2014-09-19 00:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (128 votes), past polls