in reply to Adding and Multplying Elements in an Array
Using an undef variable in a mathematical operation causes its value to begin at zero. I don't see a formal explanation in perlop, but I would speculate that under warnings or -w you see the message regarding $sum2 being uninitialized because zero times anything is zero, and perl probably figures that you want to know in advance that you're performing a computation guaranteed to result in zero. Addition works because adding to zero isn't a problem. The solution therefore is to initialize $sum2 with a non-zero value.
"The dead do not recognize context" -- Kai, Lexx
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Adding and Multplying Elements in an Array
by Dru (Hermit) on Jun 18, 2003 at 01:47 UTC | |
by Anonymous Monk on Jun 18, 2003 at 12:16 UTC |
In Section
Seekers of Perl Wisdom