Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by aaron_baugher (Curate)
on Oct 20, 2013 at 16:57 UTC ( [id://1059023]=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?

Surprised no one's added the Lisp-style recursive solution yet:

sub radd { return( defined $_[0] ? $_[0] + radd(@_[1..$#_]) : 0 ); } my $sum = radd(1..10);
  • Comment on Re: How can I add all the numbers in an array with out doing a foreach loop?
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-06-15 04:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.