Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: How can I add all the numbers in an array with out doing a foreach loop?

by ack (Deacon)
on Nov 09, 2009 at 20:32 UTC ( [id://806013]=note: print w/replies, xml ) Need Help??


in reply to How can I add all the numbers in an array with out doing a foreach loop?

Can also use map() in a side-effects fashion.

my @nums = (1,2,3,4,5); my $sum = 0; map { $sum += $_ } @nums; print "\$sum = $sum\n";

The above code prints:

$sum = 15

Originally posted as a Categorized Answer.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-25 22:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found