[oak perl] A Simple Problem
Zed Lopez
zed.lopez at gmail.com
Wed Mar 2 21:59:47 PST 2005
> my $total = 0;
> map {$total += $_} @numbers;
I prefer avoiding map in a void context, and would go for:
$total += $_ for @numbers;
Before 5.8.1, there was more point to this distinction: map built a
list that you were just discarding. Now the compiler is smart enough
that map in a void context doesn't build the list, so there's no
efficiency issue. I still find the for version more readable.
I probably wouldn't use List::Util just for this, but if I were
already using it for, say, max or min, then I'd use sum.
More information about the Oakland
mailing list