in reply to Product of a list of numbers?
However, with the loop and all, it seems like a terribly inefficient method of doing such a thing. Anyone have a smarter way?Why does it seem inefficient? It's the most straight forward way to accomplish the task. Maybe not as "elegant" (matter of opinion) as
but it's pretty much as efficient as it gets.sub product { my $list = shift; my $prod = 1; $prod *= $_ for @$list; return $prod; }
|
|---|