in reply to 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.
print sum 0, ();; 0
Similarly, passing a constant 1 as the first term to reduce if your using it to calculate product(), and the appropriate identity as the first term for other operations avoids the need for tests, or the generation of warnings.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: List::Util::sum() and empty lists...
by Fletch (Bishop) on Dec 03, 2006 at 15:19 UTC | |
|
Re^2: List::Util::sum() and empty lists...
by blazar (Canon) on Dec 04, 2006 at 08:18 UTC |