in reply to Re: List::Util::sum() and empty lists...
in thread List::Util::sum() and empty lists...
I'm not saying it's the right solution in the long term, but you can avoid the problem by always passing a constant zero as the first argument to sum. It has no affect upon the result, but does the right thing if the rest of the list is empty.
Nice trick (albeit still a trick) BrowserUk++, I must admit that simple and intuitive as it is, I hadn't thought about it: it's much lighter than say || 0, also having the big advantage of not creating problems with precedences and such.
|
|---|