Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by Sidhekin (Priest)
on Oct 31, 2001 at 23:18 UTC ( [id://122414]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use 6; # require perl v6
    use List::Util qw/reduce/;
    
    @foobar = @{reduce{[@$a ^+ @$b]}\(@foo, @bar, @baz, @etc)};
    
  2. or download this
    use List::Util qw/reduce/;
    
    @foobar = @{reduce{[map $a->[$_]+$b->[$_], 0..@$a>@$b?$#$a:$#$b]}
                       \(@foo, @bar, @baz, @etc};
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-24 07:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found