[sf-perl] reduce-like function in Perl?

Chris Palmer chris at noncombatant.org
Tue Apr 26 15:46:55 PDT 2005

Say I have a list of numbers, and I want to add them all up in one go.
Is there a reduce-like function (see Python) to do this?

    # hypothetical
    $total = reduce(+, @numbers);

I can do this, but it's aesthetically displeasing (better than foreach 
at least):

    $total = 0;
    map { $total += $_ } @numbers;

Also, what's the very fastest way to sum a bunch of numbers? I have read 
hunks of *Mastering Algorithms with Perl*, and it has good performance 
anecdotes, but I don't have it here with me now...


More information about the SanFrancisco-pm mailing list