Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
go ahead... be a heretic
 
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 making s'mores by the fire in the courtyard of the Monastery: (15)
As of 2014-04-17 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (444 votes), past polls