Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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 drinking their drinks and smoking their pipes about the Monastery: (15)
As of 2014-08-28 16:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (264 votes), past polls