You want the fastest way? My guess is it's like this:
Code:
my $total = 0;
$total += $_ for(@numbers);
Why? Jim's method might be neat, but evals tend to be slow. It still loops over the array with join(), but that's an internal loop, so it might be more optimized than a Perl for(). I'd still think that eval's overhead more than makes up for any gain. If it's a huge list of numbers where the loop might make a difference, the huge built up string can double your memory consumption.
Saying [tt]$total = $total + $_[/tt] is slower than [tt]$total += $_[/tt] because it has to look up [tt]$total[/tt]'s memory location twice (assuming Perl's compiler optimizes +=, which I'm sure they do. Anyone's who's touched assembly can see why this is).
And using a for loop (there's no semantic difference between for and foreach), when you give it a block of code to execute in { }, Perl has to create that structure of a block, scoping checks, etc. Using it as a statement modifier doesn't go through that overhead, but it's only useful for single statements (or anything that can be reduced to one).
Oh, and that List::Util I mentioned? If that were C-optimized, it'd win, hands down, but it's done in Perl. Not just that, using it is a subroutine call, expensive. What does the sum() function do internally? It makes a call to reduce(), another sub. That's probably the slowest of the lot.
Now, I haven't done any benchmarking, but I doubt there's much difference between them. Every little bit helps, though. Six stars for taking the sum of a list? jeez...
________________________________________
Andrew - Perl Monkey